NetBSD Problem Report #59060
From jkoshy@netbsd.org Sun Feb 9 21:15:29 2025
Return-Path: <jkoshy@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
client-signature RSA-PSS (2048 bits) client-digest SHA256)
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 3E03C1A923C
for <gnats-bugs@gnats.NetBSD.org>; Sun, 9 Feb 2025 21:15:29 +0000 (UTC)
Message-Id: <20250209211527.D95BE1A923D@mollari.NetBSD.org>
Date: Sun, 9 Feb 2025 21:15:27 +0000 (UTC)
From: jkoshy@NetBSD.org
Reply-To: jkoshy@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: usr.bin/m4: Don't expand bare instances of the "shift" and "m4wrap" builtins.
X-Send-Pr-Version: 3.95
>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 },
(Contact us)
$NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2025
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.