logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/
commit: 53cb7ab47c34ae3b444fac527cd22f7770ab30f9
parent d62043990191a52e74c6a4e7d285204b9cf3797b
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Thu, 24 Jul 2025 20:42:30 +0200

cmd/printf: fix write to string literal

Diffstat:

Mcmd/printf.c13+++++++++----
Mtest-cmd/printf.sh4+++-
2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/cmd/printf.c b/cmd/printf.c @@ -542,10 +542,15 @@ main(int argc, char *argv[]) break; case 'b': { - if(!fmt_arg) fmt_arg = (char *)""; - size_t arglen = strlen(fmt_arg); - - int clear = unescape(fmt_arg, &arglen, 0); + int clear = 0; + size_t arglen = 0; + if(fmt_arg) + { + arglen = strlen(fmt_arg); + clear = unescape(fmt_arg, &arglen, 0); + } + else + fmt_arg = (char *)""; if(precision > 0 && arglen > (size_t)precision) arglen = precision; 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=42 +plans=43 WD="$(dirname "$0")/../" target="${WD}/cmd/printf" . "${WD}/test-cmd/tap.sh" @@ -29,6 +29,8 @@ t_args fmt_b ' t_args fmt_b_rightpad '!{} .' '%-6b%c' '\041\x7B\x7d' . t_args fmt_b_leftpad ' !{}.' '%6b%c' '\041\x7B\x7d' . +t_args fmt_b_noarg '' '%b' + t_args fmt_q_print 'foo baré ' '%q\n' foo baré