The branch stable/13 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=c550d07d8d5f152b4b89f6c737188c30af199e3a
commit c550d07d8d5f152b4b89f6c737188c30af199e3a Author: Dag-Erling Smørgrav <[email protected]> AuthorDate: 2026-02-17 14:01:34 +0000 Commit: Dag-Erling Smørgrav <[email protected]> CommitDate: 2026-02-26 04:03:51 +0000 m4: Fix eval output width According to POSIX, the optional third argument is the minimum number of digits to print regardless of sign. We interpreted it as the minimum width of the output including the sign. Additionally, the variable used to hold this value was confusingly named “maxdigits”. PR: 293214 MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D55311 (cherry picked from commit 507c611aeac7ca9aed12353b1044bb21ab00afae) --- usr.bin/m4/eval.c | 8 ++++---- usr.bin/m4/misc.c | 2 -- usr.bin/m4/tests/eval.m4 | 2 ++ usr.bin/m4/tests/regress.eval.out | 2 ++ 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/usr.bin/m4/eval.c b/usr.bin/m4/eval.c index 82218eb9ba1c..dba903c2ba24 100644 --- a/usr.bin/m4/eval.c +++ b/usr.bin/m4/eval.c @@ -178,7 +178,7 @@ expand_builtin(const char *argv[], int argc, int td) */ { int base = 10; - int maxdigits = 0; + int mindigits = 0; const char *errstr; if (argc > 3) { @@ -189,14 +189,14 @@ expand_builtin(const char *argv[], int argc, int td) } } if (argc > 4) { - maxdigits = strtonum(argv[4], 0, INT_MAX, &errstr); + mindigits = strtonum(argv[4], 0, INT_MAX, &errstr); if (errstr) { - m4errx(1, "expr: maxdigits is %s: %s.", + m4errx(1, "expr: mindigits is %s: %s.", errstr, argv[4]); } } if (argc > 2) - pbnumbase(expr(argv[2]), base, maxdigits); + pbnumbase(expr(argv[2]), base, mindigits); break; } diff --git a/usr.bin/m4/misc.c b/usr.bin/m4/misc.c index 7d2473f88168..a6abce4936b4 100644 --- a/usr.bin/m4/misc.c +++ b/usr.bin/m4/misc.c @@ -139,8 +139,6 @@ pbnumbase(int n, int base, int d) } while ((num /= base) > 0); - if (n < 0) - printed++; while (printed++ < d) pushback('0'); diff --git a/usr.bin/m4/tests/eval.m4 b/usr.bin/m4/tests/eval.m4 index 1d3f886d0d89..dc0fada781f1 100644 --- a/usr.bin/m4/tests/eval.m4 +++ b/usr.bin/m4/tests/eval.m4 @@ -3,3 +3,5 @@ dnl expr parser eval(224&127) eval(224|127) eval(224&&127) +eval(3-2, 10, 5) +eval(2-3, 10, 4) diff --git a/usr.bin/m4/tests/regress.eval.out b/usr.bin/m4/tests/regress.eval.out index 7298b3f43840..b1bb211dcb64 100644 --- a/usr.bin/m4/tests/regress.eval.out +++ b/usr.bin/m4/tests/regress.eval.out @@ -1,3 +1,5 @@ 96 255 1 +00001 +-0001
