Skip to content

Commit 7ecc66c

Browse files
committed
Don't have UB in E0617 example
This uses an actual format string instead of passing null pointer. Closes rust-lang#86908.
1 parent 969a6c2 commit 7ecc66c

File tree

1 file changed

+4
-4
lines changed
  • compiler/rustc_error_codes/src/error_codes

1 file changed

+4
-4
lines changed

compiler/rustc_error_codes/src/error_codes/E0617.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ Erroneous code example:
44

55
```compile_fail,E0617
66
extern "C" {
7-
fn printf(c: *const i8, ...);
7+
fn printf(c: *const u8, ...) -> std::os::raw::c_int;
88
}
99
1010
unsafe {
11-
printf(::std::ptr::null(), 0f32);
11+
printf("my favourite number is %f".as_ptr(), 4_f32);
1212
// error: cannot pass an `f32` to variadic function, cast to `c_double`
1313
}
1414
```
@@ -22,9 +22,9 @@ In this case, `c_double` has the same size as `f64` so we can use it directly:
2222

2323
```no_run
2424
# extern "C" {
25-
# fn printf(c: *const i8, ...);
25+
# fn printf(c: *const u8, ...) -> std::os::raw::c_int;
2626
# }
2727
unsafe {
28-
printf(::std::ptr::null(), 0f64); // ok!
28+
printf("my favourite number is %f".as_ptr(), 4_f64); // ok!
2929
}
3030
```

0 commit comments

Comments
 (0)