The POSIX wording for m4 eval (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/m4.html) includes "The third argument, if specified, sets the minimum number of digits in the result." which mirrors the wording for specifying precision as in printf("%.*d", 4, -10) outputting "-0010" with four digits but overall width 5. GNU m4 1.4.5 changed its implementation to comply with that POSIX wording back in 2006. However, BSD m4 still behaves as if it is using printf("%0*d", 4, -10) which outputs "-010" (ie. a minimum field width with zero-padding, rather than minimum number of digits). While minor, this difference in behavior means that BSD m4 cannot always be used as a drop-in replacement to GNU m4, on tests such as: echo 'eval(-10, 10, 4) | m4'
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=507c611aeac7ca9aed12353b1044bb21ab00afae commit 507c611aeac7ca9aed12353b1044bb21ab00afae 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-17 14:01:42 +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 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(-)
A commit in branch stable/15 references this bug: 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(-)
A commit in branch stable/14 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=15717dd5c628ce57d8b73b6b8a8ea7e9d8f5e52a commit 15717dd5c628ce57d8b73b6b8a8ea7e9d8f5e52a 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:03:42 +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(-)
A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=c550d07d8d5f152b4b89f6c737188c30af199e3a commit c550d07d8d5f152b4b89f6c737188c30af199e3a 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: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(-)