17 ms·
VLQ decoding is sort of subtle, and the one shown in the article under "Base 64 Variable Length Quantities" looks broken. 1. `shift` can grow large, and an ove
by ridiculous_fish 9y ago
VLQ decoding is sort of subtle, and the one shown in the article under "Base 64 Variable Length Quantities" looks broken.
1. `shift` can grow large, and an overlong left shift will panic in Rust. I expect an input like "gggggggC" to crash.
2. `accum >>= 1` is wrong because it rounds down. It needs to be a round-towards-zero: `accum /= 2`.
3. `accum` is a 32 bit int which is too small. It needs to be larger so it can represent -2^31 in sign-magnitude form.
- mnemonik 9y agoThanks for the report! We've already fixed some of these issues[0] but I didn't update the code snippets in the article -- woops! [0] https://github.com/tromey/vlq/commit/3b41a2b6c778ce476eaaa2851a5d32e4df63a81c https://github.com/tromey/vlq/commit/3b41a2b6c778ce476eaaa28...