logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/
commit: 51df2fb18fab83c6ccae6e4ddeb9e00b40740e64
parent c562d8f046f22132621b49958ea9fe48db423962
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun, 25 Jan 2026 01:56:57 +0100

cmd/printf: drop +1 on fmt_bufi for memchr

Otherwise you end up with an error like:

   printf: error: (format position 7) flag '0' already set

with fmt_buf (static buffer) containing "%0*.*x".

Diffstat:

Mcmd/printf.c2+-
Mtest-cmd/printf.sh4+++-
2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/cmd/printf.c b/cmd/printf.c @@ -267,7 +267,7 @@ main(int argc, char *argv[]) while(fmt_bufi < sizeof(FMT_FLAGS) && fmt_idx + 1 < (fmt + fmtlen) && strchr(FMT_FLAGS, *fmt_idx) != NULL) { - if(memchr(fmt_buf, *fmt_idx, fmt_bufi + 1)) + if(memchr(fmt_buf, *fmt_idx, fmt_bufi)) { fprintf(stderr, "printf: error: (format position %d) flag '%c' already set\n", diff --git a/test-cmd/printf.sh b/test-cmd/printf.sh @@ -2,7 +2,7 @@ # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> # SPDX-License-Identifier: MPL-2.0 -plans=48 +plans=49 WD="$(dirname "$0")/../" target="${WD}/cmd/printf" . "${WD}/test-cmd/tap.sh" @@ -59,6 +59,8 @@ t_args fmt_G '10,' %G, 10 t_args fmt_a '0x1.4p+3,' %a, 10 t_args fmt_A '0X1.4P+3,' %A, 10 +t_args fmt_xxx '0x08101f' '0x%02x%02x%02x' 8 16 31 + t_args nofmtarg '[ ]' '[%s\n]'