Forráskód Böngészése

Fix QML support (#75)

* Check if index in negative before incrementing

This one is related to https://github.com/101arrowz/fflate/issues/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 <[email protected]>

* Use implicit comparison to zero

Co-authored-by: Manu MA <[email protected]>
Co-authored-by: 101arrowz <[email protected]>
Beatriz Rizental 3 éve
szülő
commit
7317216698
1 módosított fájl, 4 hozzáadás és 2 törlés
  1. 4 2
      src/index.ts

+ 4 - 2
src/index.ts

@@ -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) {
@@ -3344,4 +3346,4 @@ export function unzipSync(data: Uint8Array, opts?: UnzipOptions) {
     }
   }
   return files;
-}
+}