From 21a4b85a4ff9e0d6e171cf1097e4e168100378af Mon Sep 17 00:00:00 2001 From: Rangi Date: Sat, 22 Aug 2026 19:22:53 -0400 Subject: [PATCH] Fix `STRFMT` stopping at NUL characters in format spec strings --- src/asm/actions.cpp | 2 +- test/asm/strfmt.asm | 4 ++++ test/asm/strfmt.out | Bin 263 -> 279 bytes 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/asm/actions.cpp b/src/asm/actions.cpp index 7ab356e5..7d011b16 100644 --- a/src/asm/actions.cpp +++ b/src/asm/actions.cpp @@ -555,7 +555,7 @@ std::string act_StringFormat( std::string str; size_t argIndex = 0; - for (size_t i = 0; spec[i] != '\0';) { + for (size_t i = 0; i < spec.length();) { if (int c = spec[i]; c != '%') { str += c; ++i; diff --git a/test/asm/strfmt.asm b/test/asm/strfmt.asm index 80a16f29..1ba29982 100644 --- a/test/asm/strfmt.asm +++ b/test/asm/strfmt.asm @@ -26,3 +26,7 @@ PRINTLN STRFMT("%d eol %", 1) PRINTLN STRFMT("invalid %w spec", 42) PRINTLN STRFMT("one=%d two=%d three=%d", 1) + +DEF NUL EQUS STRFMT("%s \0 %s", "goodbye", "world") +ASSERT #NUL === "goodbye \0 world" +PRINTLN #NUL diff --git a/test/asm/strfmt.out b/test/asm/strfmt.out index 2f3ec1cc7abdaf2b28638141a750e83d487e95dc..43f452d57ccb45cb4086fce8f2a39f9bc24d3c86 100644 GIT binary patch delta 24 fcmZo?n$EO=olzh?KR+d@GF5>=p*+7RCxr_DS|A5T delta 7 OcmbQv)Xubloe=;C{sG$n