# HG changeset patch # User William Astle # Date 1703223113 25200 # Node ID b549a3a417a9a9e5168ce3532d293957ff585e8e # Parent 71ba873a0ec6f8d453a18dece795c68423c3958f 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. diff -r 71ba873a0ec6 -r b549a3a417a9 lwasm/pseudo.c --- 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);