NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/59803: sed(1) conditional branch command confuses subsequent line addressing



>Number:         59803
>Category:       bin
>Synopsis:       sed(1) conditional branch command confuses subsequent line addressing
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Nov 29 05:05:00 +0000 2025
>Originator:     elo
>Release:        NetBSD 11.0_BETA
>Organization:
>Environment:
System: NetBSD marmite.localnet 11.0_BETA NetBSD 11.0_BETA (BROADBEAN) #5: Mon Oct 27 07:39:36 GMT 2025 elo@marmite.localnet:/usr/obj/sys/arch/amd64/compile/BROADBEAN amd64
Architecture: x86_64
Machine: amd64

	$ ident /usr/bin/sed
	/usr/bin/sed:
	     $NetBSD: crt0.S,v 1.4 2018/11/26 17:37:46 joerg Exp $
	     $NetBSD: crt0-common.c,v 1.30 2025/05/02 23:04:06 riastradh Exp $
	     $NetBSD: crti.S,v 1.1 2010/08/07 18:01:35 joerg Exp $
	     $NetBSD: crtbegin.S,v 1.2 2010/11/30 18:37:59 joerg Exp $
	     $NetBSD: compile.c,v 1.55 2025/06/03 19:02:29 martin Exp $
	     $NetBSD: main.c,v 1.38 2021/03/11 15:45:55 christos Exp $
	     $NetBSD: misc.c,v 1.15 2014/06/26 02:14:32 christos Exp $
	     $NetBSD: process.c,v 1.54 2024/09/17 13:34:08 kre Exp $
	     $NetBSD: crtend.S,v 1.1 2010/08/07 18:01:34 joerg Exp $
	     $NetBSD: crtn.S,v 1.1 2010/08/07 18:01:35 joerg Exp $

>Description:
	In a sed(1) script, using the 't' command to branch when a
	substitution has been made causes a subsequent line of the script,
	qualified with an explicit address range, to be skipped for all
	remaining input if the line number of the source text in which the
	substitution was made is the same as the starting address of the
	explicit address range. Fortunately, it's much easier to demonstrate
	than it is to describe.

>How-To-Repeat:
	$ cat sedbug.sed
	#!/usr/bin/sed -nf

	=
	s,a,substitution succeeded,p
	t

	3,$ p
	# end of script

	First, exercise the script with no substitutions:
	$ echo 'b\nb\nb\nb\nb' | ./sedbug.sed
	1
	2
	3
	b
	4
	b
	5
	b

	The '=' command prints the input-line number, and the input line
	itself is printed for lines 3 and after.

	Let's have a substitution on line 2:
	$ echo 'b\na\nb\nb\nb' | ./sedbug.sed
	1
	2
	substitution succeeded
	3
	b
	4
	b
	5
	b

	The substitution succeeded, the script branched to the end and the
	subsequent lines were read and printed, as before.

	Now let's move the substitution to line 3:
	$ echo 'b\nb\na\nb\nb' | ./sedbug.sed
	1
	2
	3
	substitution succeeded
	4
	5

	By my reckoning, lines 4 and 5 ought still to have been printed,
	but they were not.

	Minised (http://exactcode.com/opensource/minised/) demonstrates
	exactly the same perplexing behaviour as NetBSD's native sed. It
	was only when I tried GNU sed and found it to act as I expected
	that I realised I might have stumbled upon a genuine anomaly (in
	two implementations of sed, no less--do NetBSD sed and minised
	have shared ancestry?).
>Fix:



Home | Main Index | Thread Index | Old Index