Browse Source

awk: fix segfault when compiled by clang

A 32-bit build of BusyBox using clang segfaulted in the test
"awk assign while assign".  Specifically, on line 7 of the test
input where the adjustment of the L.v pointer when the Fields
array was reallocated

   	L.v += Fields - old_Fields_ptr;

was out by 4 bytes.

Rearrange to code so both gcc and clang generate code that works.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Ron Yorston 3 months ago
parent
commit
e1a6874106
1 changed files with 1 additions and 1 deletions
  1. 1 1
      editors/awk.c

+ 1 - 1
editors/awk.c

@@ -3006,7 +3006,7 @@ static var *evaluate(node *op, var *res)
 			if (old_Fields_ptr) {
 				//if (old_Fields_ptr != Fields)
 				//	debug_printf_eval("L.v moved\n");
-				L.v += Fields - old_Fields_ptr;
+				L.v = Fields + (L.v - old_Fields_ptr);
 			}
 			if (opinfo & OF_STR2) {
 				R.s = getvar_s(R.v);