summaryrefslogtreecommitdiffhomepage
path: root/src/printf.c
diff options
context:
space:
mode:
authorSean Kurtz <seankurtz75@gmail.com>2026-11-28 00:50:57 -0600
committerSean Kurtz <seankurtz75@gmail.com>2026-11-28 00:50:57 -0600
commitd60c99985c1c4e058dd2de7e6272ef4d48a14686 (patch)
tree4d258260dec2c1b999868253bf50193709848d9c /src/printf.c
parent3abe682147f74104f1f1225e8c142b80018e17e7 (diff)
downloadzash-d60c99985c1c4e058dd2de7e6272ef4d48a14686.tar.gz
perf(pattern,printf): skip the class table on ASCII, a bare %s through vsnprintf
in_range() looked the two ends of `[a-z]` up in the alpha/digit tables to get alphabet order. In ASCII the code order *is* the alphabet order, so the compiler can take one comparison; the tables stay for EBCDIC. convert() formatted a bare "%s" through the spec builder and vsnprintf(), which pads, truncates and checks flags it was never given. Out it goes straight to out_puts(); anything with a flag, width or precision still takes the general path. make check unchanged (126 passed, 1 skipped, known linux/i-dscomplete); the whole suite under ASan+UBSan reports nothing.
Diffstat (limited to 'src/printf.c')
-rw-r--r--src/printf.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/printf.c b/src/printf.c
index f366f2d..fabc0b3 100644
--- a/src/printf.c
+++ b/src/printf.c
@@ -240,6 +240,10 @@ static const char *convert(printf_state *pf, const char *f) {
}
case 's': {
const char *s = next_arg(pf);
+ if (n == 1) { /* a bare "%s": there is nothing to pad or truncate */
+ out_puts(&out1, s ? s : "");
+ break;
+ }
spec[n++] = 's';
spec[n] = '\0';
out_printf(&out1, spec, s ? s : "");