wasm2c: fix allocation failure result

This commit is contained in:
Jacob Young 2024-03-23 02:50:36 +01:00
parent a7282d0910
commit c011abc4dd

View File

@ -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"