[Bug 287015] m4 should default to base 10 in eval()

[email protected] Fri, 23 May 2025 12:26:17 +0000
Newsgroups gmane.os.freebsd.devel.standards
Message-ID <[email protected]/bugzilla/>
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=287015

            Bug ID: 287015
           Summary: m4 should default to base 10 in eval()
           Product: Base System
           Version: CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: standards
          Assignee: [email protected]
          Reporter: [email protected]

POSIX says:
https://pubs.opengroup.org/onlinepubs/9799919799/utilities/m4.html
The second argument, if specified, shall set the radix for the result; if the
argument is blank or unspecified, the default is 10.

Yet it appears that the implementation is trying to treat a blank argument as
base 0, in contrast to GNU m4:

$ echo 'eval(1,,2)' | m4 -g
m4bsd: stdin at line 1: expr: base is too small: .
$ echo 'eval(1,,2)' | gm4
01

The following patch addresses the problem:

diff --git i/usr.bin/m4/eval.c w/usr.bin/m4/eval.c
index 1ec111a3eb92..24daa8ecf9e4 100644
--- i/usr.bin/m4/eval.c
+++ w/usr.bin/m4/eval.c
@@ -213,7 +213,7 @@ expand_builtin(const char *argv[], int argc, int td)
                int maxdigits = 0;
                const char *errstr;

-               if (argc > 3) {
+               if (argc > 3 && *argv[3]) {
                        base = strtonum(argv[3], 2, 36, &errstr);
                        if (errstr) {
                                m4errx(1, "expr: base is %s: %s.",

-- 
You are receiving this mail because:
You are the assignee for the bug.