setexpr: Correct dropping of final unmatched string

At present the 'nlen' variable increases with each loop. If the previous
loop had back references, then subsequent loops without back references
use the wrong value of nlen. The value is larger, meaning that the string
terminator from nbuf is copied along to the main buffer, thus terminating
the string prematurely.

This leads to the final result being truncated, e.g. missing the last
(unmatched) part of the string. So "match match tail" become
"replaced replaced" instead of "replaced replaced tail".

Fix this by resetting nlen to the correct value each time around the lop.

Fixes: 855f18ea0e6 ("setexpr: add regex substring matching and substitution")
Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/test/cmd/setexpr.c b/test/cmd/setexpr.c
index a6940fd..d06dda2 100644
--- a/test/cmd/setexpr.c
+++ b/test/cmd/setexpr.c
@@ -277,12 +277,11 @@
 	ut_assertok(setexpr_regex_sub(buf, BUF_SIZE, nbuf, BUF_SIZE,
 				      "(this) (is) (surely|indeed)",
 				      "us \\1 \\2 \\3!", true));
-
-	/* The following checks fail at present due to bugs in setexpr */
-	return 0;
 	ut_asserteq_str("us this is surely! a test is it? yes us this is indeed! a test",
 			buf);
 
+	/* The following checks fail at present due to a bug in setexpr */
+	return 0;
 	for (i = BUF_SIZE; i < 0x1000; i++) {
 		ut_assertf(buf[i] == (char)i,
 			   "buf byte at %x should be %02x, got %02x)\n",