One function

VarInt in construct/construct

The author described this change as VarInt fixed, bug #705 returning modified non-original value from build. It counts as a record because the check below fails on the code as it stood at 4546be4ab and passes on bc911f685, with nothing else changed between the two runs.

Fix saved2018-04-02
Sharing licenceMIT · LICENSE
Change size+5 4

What the code was meant to do, written into the code itself as a docstring

VarInt encoded integer. Each 7 bits of the number are encoded in one byte of the stream, where leftmost bit (MSB) is unset when byte is terminal. Scheme is defined at Google site related to `Protocol Buffers <https://developers.google.com/protocol-buffers/docs/encoding>`_. Can only encode non-negative numbers. Parses into an integer. Builds from an integer. Size is undefined. :raises StreamError: requested reading negative amount, could not read enough bytes, requested writing different amount than actual data, or could not write all bytes :raises IntegerError: given a negative value, or not an integer Example::

The change

3434 raise IntegerError("value is not an integer")
3535 if obj < 0:
3636 raise IntegerError("varint cannot build from negative number: %r" % (obj,))
37- while obj > 0b01111111:
38- stream_write(stream, int2byte(0b10000000 | (obj & 0b01111111)), 1)
39- obj >>= 7
40- stream_write(stream, int2byte(obj), 1)
37+ x = obj
38+ while x > 0b01111111:
39+ stream_write(stream, int2byte(0b10000000 | (x & 0b01111111)), 1)
40+ x >>= 7
41+ stream_write(stream, int2byte(x), 1)
4142 return obj
4243
4344 def _emitprimitivetype(self, ksy, bitwise):

The check that tells the two apart

failpass·tests/test_core.py::test_varint_issue_705

Check file tests/test_core.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it4546be4ab42ebbb02aff263300cd34f21740f13d
Broken version dated2018-03-31
Moduleconstruct.core
Units changedVarInt
Fingerprint58b0dfae92acddf3
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in construct/construct