From 042520e46621e434c9bd2da6b100b32ccdee55a5 Mon Sep 17 00:00:00 2001
From: Ron Yorston <rmy@pobox.com>
Date: Fri, 19 Jan 2024 15:19:49 +0000
Subject: 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.

This patch has been submitted upstream.  Until it's accepted there
the new code is only used in builds for Windows.
---
 editors/awk.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/editors/awk.c b/editors/awk.c
index 3ca0c5fce..8d88fce76 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -3029,7 +3029,11 @@ static var *evaluate(node *op, var *res)
 			if (old_Fields_ptr) {
 				//if (old_Fields_ptr != Fields)
 				//	debug_printf_eval("L.v moved\n");
+#if !ENABLE_PLATFORM_MINGW32
 				L.v += Fields - old_Fields_ptr;
+#else
+				L.v = Fields + (L.v - old_Fields_ptr);
+#endif
 			}
 			if (opinfo & OF_STR2) {
 				R.s = getvar_s(R.v);
-- 
cgit v1.2.3-55-g6feb