Skip to content

fix bug in utils.leInt2Buff #28 #72

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

Merged
merged 2 commits into from
Oct 25, 2022
Merged

fix bug in utils.leInt2Buff #28 #72

merged 2 commits into from
Oct 25, 2022

Conversation

nooma-42
Copy link
Contributor

@nooma-42 nooma-42 commented Sep 24, 2022

What type of PR is this?

Bug Fix


What does this PR do? Why is it needed?

issue #28 pointed out What type of PR is this?

Bug Fix


What does this PR do? Why is it needed?

issue #28 pointed out leInt2Buff return depend on len, and make an explanation on why this could be potentially harmful to user not familiar with library. This bug is fixed by rearrange the function arguments.

issue #28 showed the output from the first piece of code, the truncated results of its script is now normal without any trailing 1.

num:  42n
leInt2Buff len = undefined:  Uint8Array(1) [ 42 ]
leInt2Buff len = 1:  Uint8Array(1) [ 42 ]
leInt2Buff len = 2:  Uint8Array(2) [ 42, 0 ]
leInt2Buff len = 3:  Uint8Array(3) [ 42, 0, 0 ]
leInt2Buff len = 4:  Uint8Array(4) [ 42, 0, 0, 0 ]
leInt2Buff len = 5:  Uint8Array(5) [ 42, 0, 0, 0, 0 ]
leInt2Buff len = 6:  Uint8Array(6) [ 42, 0, 0, 0, 0, 0 ]
leInt2Buff len = 7:  Uint8Array(7) [
  42, 0, 0, 0,
   0, 0, 0
]
leInt2Buff len = 8:  Uint8Array(8) [
  42, 0, 0, 0,
   0, 0, 0, 0
]


Which issues(s) does this PR fix?

bug in utils.leInt2Buff #28


Other notes for review

@phated
Copy link
Contributor

phated commented Oct 14, 2022

@nooma-42 This looks great! Can you add some tests for it?

@nooma-42
Copy link
Contributor Author

@nooma-42 This looks great! Can you add some tests for it?

I've added tests for leInt2Buff and BeInt2Buff, testing with the case introduced in original issue (28)
I also corrected a typo in src/util.js

Before I made the commit, the code below will never run, since it's same condition as previous clause.

else if (i + 4 <= buff.length) {

@jbaylina jbaylina merged commit ba98c65 into iden3:master Oct 25, 2022
@phated phated mentioned this pull request Nov 4, 2022
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