Skip to content

Commit c54e1f1

Browse files
authored
Merge pull request #1839 from folkertdev/c-variadic-unsafe-at-any-speed
add a warning about using `safe` on extern c-variadic functions
2 parents 056d4e6 + c13d2d2 commit c54e1f1

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/items/external-blocks.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,15 @@ unsafe extern "C" {
179179
unsafe fn foo(...);
180180
unsafe fn bar(x: i32, ...);
181181
unsafe fn with_name(format: *const u8, args: ...);
182+
// SAFETY: This function guarantees it will not access
183+
// variadic arguments.
184+
safe fn ignores_variadic_arguments(x: i32, ...);
182185
}
183186
```
184187

188+
> [!WARNING]
189+
> The `safe` qualifier should not be used on a function in an `extern` block unless that function guarantees that it will not access the variadic arguments at all. Passing an unexpected number of arguments or arguments of unexpected type to a variadic function may lead to [undefined behavior][undefined].
190+
185191
r[items.extern.attributes]
186192
## Attributes on extern blocks
187193

0 commit comments

Comments
 (0)