Skip to content

Commit 83405a5

Browse files
committed
fix off-by-one err
1 parent 4398afe commit 83405a5

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/server/encode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ impl Encoder {
255255
let buf_len = buf.len().checked_sub(self.bytes_read).unwrap_or(0);
256256
let amt = src.len().min(buf_len);
257257
// Calculate the max char count encoding the `len_prefix` statement
258-
// as hex would take. This is done by rounding up `log16(amt)`.
259-
let hex_len = (amt as f64).log(16.0).ceil() as usize;
258+
// as hex would take. This is done by rounding up `log16(amt + 1)`.
259+
let hex_len = ((amt + 1) as f64).log(16.0).ceil() as usize;
260260
let crlf_len = 2 * 2;
261261
let buf_upper = buf_len.checked_sub(hex_len + crlf_len).unwrap_or(0);
262262
let amt = amt.min(buf_upper);

0 commit comments

Comments
 (0)