You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's adjust this language so that it talks about the guarantees that
the function must make, and so that it says what may lead to UB rather
than what "is" UB, as the latter implies immediate language UB, when
this is actually library UB.
Let's also add a `SAFETY` comment to the function in the example.
Copy file name to clipboardExpand all lines: src/items/external-blocks.md
+3-1Lines changed: 3 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -179,12 +179,14 @@ unsafe extern "C" {
179
179
unsafefnfoo(...);
180
180
unsafefnbar(x:i32, ...);
181
181
unsafefnwith_name(format:*constu8, args:...);
182
+
// SAFETY: This function guarantees it will not access
183
+
// variadic arguments.
182
184
safefnignores_variadic_arguments(x:i32, ...);
183
185
}
184
186
```
185
187
186
188
> [!WARNING]
187
-
> `safe` should only be used in cases where the function does not look at the variadic arguments at all. Passing an unexpected number of arguments or arguments of an unexpected type to a variadic function is[undefined behavior][undefined].
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].
0 commit comments