This was noticed when building expr in coreutils
with -fsanitize=memory, which induced false failures
resulting in an infinite loop.

* tests/init.sh: Break from the loop if there's an issue with expr(1).
---
 ChangeLog     | 5 +++++
 tests/init.sh | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 986ff2fa4d..36a5838419 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2025-09-15  Pádraig Brady  <[email protected]>
+
+       tests: avoid infinite loop in init.sh
+       * tests/init.sh: Break from the loop if there's an issue with expr(1).
+
 2025-09-15  Pádraig Brady  <[email protected]>
 
        cpu-supports: relicense under LGPL
diff --git a/tests/init.sh b/tests/init.sh
index 2058822627..6a63f05ee9 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -394,7 +394,7 @@ mktempd_ ()
     err_=`mkdir -m 0700 "$candidate_dir_" 2>&1` \
       && { echo "$candidate_dir_"; return; }
     test $MAX_TRIES_ -le $i_ && break;
-    i_=`expr $i_ + 1`
+    i_=`expr $i_ + 1` || break
   done
   fail_ "$err_"
 }
-- 
2.50.1


Reply via email to