From 3d3b621ff1f3b1b58d201499596e129934b07716 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deuc=D0=B5?= <shurd@sasktel.net> Date: Thu, 16 Jan 2025 11:25:27 -0500 Subject: [PATCH] Fix fencepost error in format arguments. The first argument after the list was still being replaced. Extended test to try the hard stuff. --- exec/tests/global/format.js | 6 +++++- src/sbbs3/js_sprintf.c | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/exec/tests/global/format.js b/exec/tests/global/format.js index 31610ab51c..9921b92e3b 100644 --- a/exec/tests/global/format.js +++ b/exec/tests/global/format.js @@ -1,4 +1,4 @@ -const args = [ 1, 1.1, true, "one", -1, 1e9 ]; +const args = [ 1, 1.1, true, "one", -1, 1e9, null ]; const test = { "%s": "1", @@ -18,6 +18,10 @@ const test = { "%5$d": "-1", "%5$x": "ffffffff", "%6$u": "1000000000", + "%7$u": "0", + "%7$s": "null", + "%7$s %s": "null %s", + "%8$s": "%8$s", }; for (var i in test) { diff --git a/src/sbbs3/js_sprintf.c b/src/sbbs3/js_sprintf.c index dff931d69d..90a846ea8f 100644 --- a/src/sbbs3/js_sprintf.c +++ b/src/sbbs3/js_sprintf.c @@ -48,7 +48,7 @@ js_sprintf(JSContext *cx, uint argn, uintN argc, jsval *argv) cur = next; else cur++; - if (cur > argc) + if (cur >= argc) break; if (JSVAL_IS_DOUBLE(argv[cur])) p = xp_asprintf_next(p, XP_PRINTF_CONVERT | XP_PRINTF_TYPE_DOUBLE, JSVAL_TO_DOUBLE(argv[cur])); -- GitLab