Mercurial > hg > index.cgi
diff lwasm/pseudo.c @ 568:b549a3a417a9
Fix some additional glitches in implementation of includebin offset/length
The usage of the "len" element of the line structure to pass information
forward is invalid and may cause weird problems. Instead, use the two
"lint" and "lint2" values to pass information forward and only set the
"len" element when the final length is known.
author | William Astle <lost@l-w.ca> |
---|---|
date | Thu, 21 Dec 2023 22:31:53 -0700 |
parents | 71ba873a0ec6 |
children | 2ac2d447a2fa |
line wrap: on
line diff
--- a/lwasm/pseudo.c Thu Dec 21 22:23:39 2023 -0700 +++ b/lwasm/pseudo.c Thu Dec 21 22:31:53 2023 -0700 @@ -1522,7 +1522,7 @@ flen = ftell(fp); fclose(fp); - l -> len = flen; + l -> lint2 = flen; if (**p == ',') { @@ -1541,6 +1541,10 @@ lwasm_save_expr(l, 1, e1); } } + else + { + l -> len = flen; // length is resolved + } } RESOLVEFUNC(pseudo_resolve_includebin) @@ -1562,10 +1566,10 @@ i = lw_expr_intval(e); if (i < 0) - i = l -> len + i; + i = l -> lint2 + i; } - i1 = l -> len - i; + i1 = l -> lint2 - i; e1 = lwasm_fetch_expr(l, 1); @@ -1581,7 +1585,7 @@ return; } - if (i > l -> len) + if (i > l -> lint2) { /* starts past end of file */ lwasm_register_error(as, l, E_INCLUDEBIN_ILL_START); @@ -1595,7 +1599,7 @@ return; } - if (i + i1 > l -> len) + if (i + i1 > l -> lint2) { /* read past end of file */ lwasm_register_error(as, l, E_INCLUDEBIN_ILL_LENGTH);