clickhouse-rs icon indicating copy to clipboard operation
clickhouse-rs copied to clipboard

FixedString seems broken

Open dzbarsky opened this issue 2 years ago • 0 comments

This line doesn't seem correct to me: https://github.com/suharev7/clickhouse-rs/blob/b7f0df499ee1e1390e84c38cf2ccffef3ce7c612/src/types/column/fixed_string.rs#L70

Let's take a closer look at the implementation:

    fn push(&mut self, value: Value) {
        let bs: String = String::from(value);
        let l = cmp::min(bs.len(), self.str_len);
        let old_len = self.buffer.len();
        self.buffer.extend_from_slice(&bs.as_bytes()[0..l]);
        self.buffer.resize(old_len + (self.str_len - l), 0_u8);
    }

In the case when the string in value is of the correct size, l = self.str_len() and we extend self.buffer with the new string, then we proceed to call self.buffer.resize(old_len, 0u8) which truncates the buffer to what it was before we did the write. We should probably resize starting at the new length, not the old one?

dzbarsky avatar Dec 25 '21 19:12 dzbarsky