jamesmunns / postcard

A no_std + serde compatible message library for Rust
Apache License 2.0
788 stars 76 forks source link

Minor: Fix off-by-one in varint size calculation #111

Closed Palladinium closed 10 months ago

Palladinium commented 11 months ago

I was reading through the varint implementation in postcard to sanity-check one of my own implementations, and I spotted a mistake in the code that calculates the maximum number of varint bytes an integer datatype can take.

The old version adds 7 instead of 6, so instead of the behaviour documented in the comment it would overestimate the number of varint bytes required by one for datatypes whole size is a multiple of 7 bits. Since there are thankfully none among the common integer datatypes, the behaviour is correct both before and after the change.

netlify[bot] commented 11 months ago

Deploy Preview for cute-starship-2d9c9b processing.

Name Link
Latest commit 67a7e7431542335d4a2c1f978de74c6cbd626a00
Latest deploy log https://app.netlify.com/sites/cute-starship-2d9c9b/deploys/64e42e2e7c7d84000883cff9
netlify[bot] commented 11 months ago

Deploy Preview for cute-starship-2d9c9b canceled.

Name Link
Latest commit 67a7e7431542335d4a2c1f978de74c6cbd626a00
Latest deploy log https://app.netlify.com/sites/cute-starship-2d9c9b/deploys/64e42e2e7c7d84000883cff9
jamesmunns commented 10 months ago

Thanks, great catch!