Date: Thu, 26 Feb 2026 04:22:46 +0000 From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 8124bd4524a2 - stable/15 - m4: Fix eval output width Message-ID: <699fca96.373e7.6221e272@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch stable/15 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=8124bd4524a299a647fb25f8d4ebe2cfe6846a59 commit 8124bd4524a299a647fb25f8d4ebe2cfe6846a59 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2026-02-17 14:01:34 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2026-02-26 04:02:28 +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 4e45a71874e1..0963a61a2914 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 && *argv[3] != '\0') { @@ -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 3091f2ad1f9e..fd72292aeac0 100644 --- a/usr.bin/m4/misc.c +++ b/usr.bin/m4/misc.c @@ -138,8 +138,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 +-0001home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?699fca96.373e7.6221e272>
