Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix / Inconsistency: Respect Uint8Array offsets #826

Merged
merged 1 commit into from
May 31, 2021

Conversation

trgwii
Copy link
Contributor

@trgwii trgwii commented Mar 31, 2021

Okay, so found a potential bug in std:

import { varnum } from "https://deno.land/std@0.91.0/encoding/binary.ts";

const main = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
const sub = main.subarray(4, 8);
console.log(varnum(sub, { dataType: "uint8" })); // logs 1

This PR should only affect varnum() and friends operating on Uint8Array subarrays where the offset is > 0.

I replaced all hardcoded 0 indices in the relevant functions with b.byteOffset to get the desired behavior of logging 5 in the above example.

I also added a test for my change (note that this only tests varnum, and not all the relevant functions).

@CLAassistant
Copy link

CLAassistant commented Mar 31, 2021

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@lucacasonato lucacasonato merged commit 3eea49d into denoland:main May 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants