NetBSD Problem Report #59050
From www@netbsd.org Thu Feb 6 22:46:55 2025
Return-Path: <www@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)
client-signature RSA-PSS (2048 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 9EE9B1A923A
for <gnats-bugs@gnats.NetBSD.org>; Thu, 6 Feb 2025 22:46:55 +0000 (UTC)
Message-Id: <20250206224654.548161A923C@mollari.NetBSD.org>
Date: Thu, 6 Feb 2025 22:46:54 +0000 (UTC)
From: carsten.reith@t-online.de
Reply-To: carsten.reith@t-online.de
To: gnats-bugs@NetBSD.org
Subject: Discrepancy between ed behaviour and man page and POSIX
X-Send-Pr-Version: www-1.0
>Number: 59050
>Category: bin
>Synopsis: Discrepancy between ed behaviour and man page and POSIX
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Feb 06 22:50:00 +0000 2025
>Last-Modified: Thu Feb 06 23:40:01 +0000 2025
>Originator: Carsten Reith
>Release: 10.1-STABLE
>Organization:
>Environment:
NetBSD mogli.creith.de 10.1_STABLE NetBSD 10.1_STABLE (MOGLI) #0: Thu Feb 6 17:48:39 CET 2025 creith@mogli.creith.de:/home/creith/netbsd/obj/sys/arch/amd64/compile/MOGLI amd64
>Description:
According to the man page and POSIX, a missing trailing delimiter in a substitution should be equivalent to <delimter>p (f.ex. /p). This doesn't work with % (repeat last substitution.)
>How-To-Repeat:
mogli$ printf "a\nb\nc\n" > test
mogli$ ed test
6
1s/a/hello
hello
2s/b/%
%
,n
1 hello
2 %
3 c
>Fix:
After applying the following diff, ed works as expected.
Index: sub.c
===================================================================
RCS file: /cvsroot/src/bin/ed/sub.c,v
retrieving revision 1.7
diff -u -r1.7 sub.c
--- sub.c 23 Mar 2014 05:06:42 -0000 1.7
+++ sub.c 6 Feb 2025 22:18:46 -0000
@@ -84,7 +84,8 @@
char c;
char delimiter = *ibufp++;
- if (*ibufp == '%' && *(ibufp + 1) == delimiter) {
+ if (*ibufp == '%' &&
+ (*(ibufp + 1) == delimiter || *(ibufp + 1) == '\n')) {
ibufp++;
if (!rhbuf) {
seterrmsg("no previous substitution");
Ed session after diff:
mogli$ printf "a\nb\nc\n" > test
mogli$ ed test
6
,n
1 a
2 b
3 c
1s/a/hello
hello
2s/b/%
hello
.n
2 hello
,n
1 hello
2 hello
3 c
>Audit-Trail:
From: Martin Neitzel <neitzel@marshlabs.gaertner.de>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: bin/59050
Date: Fri, 7 Feb 2025 00:39:28 +0100 (CET)
+1 for this fix. It applies to -current and all releases (stable branches).
(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.