rust-rdkafka icon indicating copy to clipboard operation
rust-rdkafka copied to clipboard

Remove nul chars from string before parsing to numerical values

Open KowalczykBartek opened this issue 8 months ago • 1 comments

Looks like this change https://github.com/fede1024/rust-rdkafka/commit/353812ff958b4b65f9e65dd22a60e770ed6ba948 is causing following error (when SimpleConsumer is being run) - at least on OSX

librdkafka validated config value is valid u64: ParseIntError { kind: InvalidDigit }

That is because rd_kafka_conf_get returns null terminated string,

// Allocate a buffer of that size and call again to get the actual
// string.
let mut buf = vec![0_u8; size];
let res = unsafe {
    rdsys::rd_kafka_conf_get(
        self.ptr(),
        key_c.as_ptr(),
        buf.as_mut_ptr() as *mut c_char,
        &mut size,
    )
};

ends with buf equal:

[51, 48, 48, 48, 48, 48, 0];

I guess reverting this change will cause issues on windows, so maybe my PR will be good enough to handle this.

This pr should also fix this case https://github.com/fede1024/rust-rdkafka/pull/683

KowalczykBartek avatar May 29 '24 17:05 KowalczykBartek