NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
bin/59060: usr.bin/m4: Don't expand bare instances of the "shift" and "m4wrap" builtins.
>Number: 59060
>Category: bin
>Synopsis: usr.bin/m4: Don't expand bare instances of the "shift" and "m4wrap" builtins.
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Feb 09 21:20:00 +0000 2025
>Originator: Joseph Koshy
>Release: NetBSD 10.99.*
>Organization:
NetBSD Project
>Environment:
System: NetBSD nbc 10.99.12 NetBSD 10.99.12 (GENERIC) #0: Sat Feb 8 19:03:09 GMT 2025 jkoshy@nbc:/usr/obj/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
usr.bin/m4: Don't expand bare instances of the "shift" and "m4wrap" builtins.
POSIX leaves the output of the "shift" or "m4wrap" M4 builtins
undefined if these are not immediately followed by an open parenthesis.
For such 'bare' uses, GNU M4 passes the keyword to the output
unexpanded but NetBSD's M4 expands them to the empty string:
GNUM4: "shift" -> "shift" # Bare keyword is passed through.
GNUM4: "shift(1,2,3)" -> "2,3" # Per POSIX.
NBM4: "shift" -> "" # Bare keyword expands to the empty string.
NBM4: "shift(1,2,3)" -> "2,3" # Per POSIX.
and similarly for "m4wrap".
GNU M4's behavior seems more sensible to me. This change aligns
the behavior of NetBSD's M4 with GNU.
The change should be a no-op for the NetBSD source tree. A quick
grep through the sources did not show 'bare' uses of the "shift"
and "m4wrap" keywords except in comments. The existing uses of
these M4 builtins in the tree seem to use the proper macro invocation
syntax (i.e. as shift(..args..) or m4_shift(..args..)). This is
as expected since 'bare' uses of these keywords would anyway be
non-portable.
Tested:
- 'make test' in /usr/src/tests/usr.bin/m4
- With a "./build.sh distribution" followed by a boot into the
new userland and new kernel (but only x86).
>How-To-Repeat:
% echo "shift;m4wrap" | gm4
shift;m4wrap
% echo "shift;m4wrap" | m4
;
%
>Fix:
Index: main.c
===================================================================
RCS file: /cvsroot/src/usr.bin/m4/main.c,v
retrieving revision 1.50
diff -u -u -r1.50 main.c
--- main.c 25 Jun 2020 02:25:53 -0000 1.50
+++ main.c 9 Feb 2025 19:02:01 -0000
@@ -131,14 +131,14 @@
{ "popdef", POPDTYPE },
{ "pushdef", PUSDTYPE },
{ "dumpdef", DUMPTYPE | NOARGS },
- { "shift", SHIFTYPE | NOARGS },
+ { "shift", SHIFTYPE },
{ "translit", TRNLTYPE },
{ "undefine", UNDFTYPE },
{ "undivert", UNDVTYPE | NOARGS },
{ "divnum", DIVNTYPE | NOARGS },
{ "maketemp", MKTMTYPE },
{ "errprint", ERRPTYPE | NOARGS },
- { "m4wrap", M4WRTYPE | NOARGS },
+ { "m4wrap", M4WRTYPE },
{ "m4exit", EXITTYPE | NOARGS },
{ "syscmd", SYSCTYPE },
{ "sysval", SYSVTYPE | NOARGS },
Home |
Main Index |
Thread Index |
Old Index