Repository navigation
Conversation
Just use integer division instead of floor/ceil to determine buffer sizes. Add more tests.
|
@iliaal Could you take a look at this? I am not sure it is much of an improvement to remove floor/ceil. What do you think? |
iliaal
left a comment
There was a problem hiding this comment.
I think it's an improvement: floor(len * 1.33) only works because 1.33 is close enough to 4/3 for the line lengths uuencode allows, while ((len + 2) / 3) * 4 is the exact encoded length. I diffed old and new decoders on random input and on truncated or mutated encodings and got identical results.
One problem: src_len * 3 can overflow on 32-bit, where the double version could not.
Co-authored-by: Ilia Alshanetsky <ilia@ilia.ws>
|
I fuzzed base against head, round-trip and malformed input, byte-identical on gcc and clang. That includes the inputs where floor(len*1.33) and ((len+2)/3)*4 disagree. The decode loop bounds mask the difference, so output stays the same. ASan is clean, including a 5 MB round-trip. You asked whether it's much of an improvement. On speed, no: decode instructions are flat, gcc 13 encode is about 4% more, and cycles are lost in the noise at this size. The real gain is the exact formula, which drops the len==45 special case and the double-precision risk in the decode allocation for huge inputs. LGTM. |
Just use integer division instead of floor/ceil to determine buffer sizes. Add more tests.