Skip to content

ByteBuffer.writeVarint64 truncating value to 32 bits. #22

@cawilson

Description

@cawilson

Whilst testing the new version, I've noticed that when a number that is greater than 32 bits is written as a Varint64, the code is truncating the value to 32 bits.

ByteBuffer.prototype.writeVarint64 = function(value, offset) {
    ...
    if (!this.noAssert) {
        if (typeof value === 'number' && value % 1 === 0)
            value |= 0; // This is truncating the value to 32 bits.
        ...
    }
    ...
};

I have tested this in IE 11, Chrome 35 and FF 31 with the same result.

An example is:

var value = 13270440001;
value |= 0; // value is now: 385538113

I've also noticed that this same operation is used a few times throughout the new version and I'm wondering if similar issues will arise. I can see that the resize method performs the same operation on the capacity and thus this would artificially limit the capacity.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions