]> git.kaiwu.me - quickjs.git/commitdiff
Fix UB left shift of negative number
authorBen Noordhuis <info@bnoordhuis.nl>
Wed, 1 Nov 2023 05:53:16 +0000 (06:53 +0100)
committerBen Noordhuis <info@bnoordhuis.nl>
Sat, 17 Feb 2024 16:36:50 +0000 (17:36 +0100)
quickjs.c

index c3db0385d1c65918764d32a8c8ddac3fb2768fbd..2c1ac6bd662972c18aeb9d33eecd853272e22202 100644 (file)
--- a/quickjs.c
+++ b/quickjs.c
@@ -34907,7 +34907,7 @@ static int JS_WriteBigNum(BCWriterState *s, JSValueConst obj)
         e = a->expn + 3;
     else
         e = a->expn;
-    e = (e << 1) | a->sign;
+    e = (e * 2) | a->sign;
     if (e < INT32_MIN || e > INT32_MAX) {
         JS_ThrowInternalError(s->ctx, "bignum exponent is too large");
         return -1;