Commit cb71e7c
committed
Use CStr::from_bytes_until_nul to read rdkafka config
Commit 353812f replaced the more finicky
`CStr::from_bytes_with_nul` with `String::from_utf8_lossy`.
That eliminated a panic but the returned Rust string now contained NUL bytes.
This might have accidentally worked in FFI APIs that take C strings, but it
fails when such a string is passed to a Rust API, such as integer parsing in
`stream_consumer.rs:217`.
The newer `CStr::from_bytes_until_nul` function
1. does not panic
2. ends the string at the first NUL byte
It does return an error when there is no NUL byte in the input slice.
While it would be possible to fall back to `String::from_utf8_lossy` in that
case, I'm not sure that would be a good idea. If we are in that situation,
librdkafka clearly has messed something up completely. The contents of the
buffer are then more likely complete garbage.1 parent e69c2aa commit cb71e7c
1 file changed
+4
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
153 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
154 | 157 | | |
155 | 158 | | |
156 | 159 | | |
| |||
0 commit comments