Commit c011abc4dd

Jacob Young <jacobly0@users.noreply.github.com>
2024-03-23 02:50:36
wasm2c: fix allocation failure result
1 parent a7282d0
Changed files (1)
stage1
stage1/wasm2c.c
@@ -261,13 +261,13 @@ int main(int argc, char **argv) {
           "    uint8_t *new_m = *m;\n"
           "    uint32_t r = *p;\n"
           "    uint32_t new_p = r + n;\n"
-          "    if (new_p > UINT32_C(0x10000)) return UINT32_C(0xFFFFFFF);\n"
+          "    if (new_p > UINT32_C(0xFFFF)) return UINT32_C(0xFFFFFFFF);\n"
           "    uint32_t new_c = *c;\n"
           "    if (new_c < new_p) {\n"
           "        do new_c += new_c / 2 + 8; while (new_c < new_p);\n"
-          "        if (new_c > UINT32_C(0x10000)) new_c = UINT32_C(0x10000);\n"
+          "        if (new_c > UINT32_C(0xFFFF)) new_c = UINT32_C(0xFFFF);\n"
           "        new_m = realloc(new_m, new_c << 16);\n"
-          "        if (new_m == NULL) return UINT32_C(0xFFFFFFF);\n"
+          "        if (new_m == NULL) return UINT32_C(0xFFFFFFFF);\n"
           "        *m = new_m;\n"
           "        *c = new_c;\n"
           "    }\n"