NetBSD-Bugs archive

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

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



The following reply was made to PR bin/59803; it has been noted by GNATS.

From: RVP <rvp%SDF.ORG@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: 
Subject: Re: bin/59803: sed(1) conditional branch command confuses subsequent
 line addressing
Date: Sun, 30 Nov 2025 13:26:41 +0000 (UTC)

 On Sat, 29 Nov 2025, elo%sdf.org@localhost wrote:
 
 > 	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.
 >
 
 Yes, it seems that way to me too. This affects `b' too:
 
 ```
 $ printf '%s\n' one two three four five six | sed -n $'=\n3b\n3,5p'
 1
 2
 3
 4
 5
 6
 $
 ```
 
 > Fix:
 >
 
 ```
 diff -urN sed.orig/process.c sed/process.c
 --- sed.orig/process.c	2024-09-18 04:04:51.056653673 +0000
 +++ sed/process.c	2025-11-30 12:47:21.934353983 +0000
 @@ -331,7 +331,9 @@
   				} else
   					r = 1;
   			}
 -		} else if (cp->a1 && MATCH(cp->a1)) {
 +		} else if (cp->a1 && (MATCH(cp->a1) ||
 +		           (cp->a1->type == AT_LINE &&
 +			    linenum >= cp->a1->u.l && linenum <= cp->a2->u.l))) {
   			/*
   			 * If the second address is a number less than or
   			 * equal to the line number first selected, only
 ```
 
 ATF tests except for the overlapping ranges test (which'll need adjustment
 because sed(1) now behaves like the GNU sed).
 
 -RVP
 


Home | Main Index | Thread Index | Old Index