Skip to content

Commit

Permalink
Fix QML support (#75)
Browse files Browse the repository at this point in the history
* Check if index in negative before incrementing

This one is related to #71 :) After the `setTiemout` issues was sorted I found antoher one.

In the hMap function there is a moment where the program may try to access a negative index. Although in Node.js and browser that does not raise an error, in QML it does raise a TypeError.

Good thing is after this fix it all works over there. 

I was not able to run the complete fflate test suite in my machine, so hopefully this works fine.

* Update src/index.ts

Co-authored-by: Manu MA <manu.valladolid@gmail.com>

* Use implicit comparison to zero

Co-authored-by: Manu MA <manu.valladolid@gmail.com>
Co-authored-by: 101arrowz <arjunbarrett@gmail.com>
  • Loading branch information
3 people committed Jun 17, 2021
1 parent b786929 commit 7317216
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/index.ts
Expand Up @@ -66,7 +66,9 @@ const hMap = ((cd: Uint8Array, mb: number, r: 0 | 1) => {
// u16 "map": index -> # of codes with bit length = index
const l = new u16(mb);
// length of cd must be 288 (total # of codes)
for (; i < s; ++i) ++l[cd[i] - 1];
for (; i < s; ++i) {
if (cd[i]) ++l[cd[i] - 1];
}
// u16 "map": index -> minimum code for bit length = index
const le = new u16(mb);
for (i = 0; i < mb; ++i) {
Expand Down Expand Up @@ -3344,4 +3346,4 @@ export function unzipSync(data: Uint8Array, opts?: UnzipOptions) {
}
}
return files;
}
}

0 comments on commit 7317216

Please sign in to comment.