changeset 53719:824b5057fbca

(Freplace_match): Handle nonexistent back-references properly.
author Richard M. Stallman <rms@gnu.org>
date Tue, 27 Jan 2004 04:52:09 +0000
parents 2a5b1c27f1a5
children f4286b8e9196
files src/search.c
diffstat 1 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/search.c	Tue Jan 27 04:52:02 2004 +0000
+++ b/src/search.c	Tue Jan 27 04:52:09 2004 +0000
@@ -2366,13 +2366,21 @@
 		      substart = search_regs.start[sub];
 		      subend = search_regs.end[sub];
 		    }
-		  else if (c >= '1' && c <= '9' && c <= search_regs.num_regs + '0')
+		  else if (c >= '1' && c <= '9')
 		    {
-		      if (search_regs.start[c - '0'] >= 0)
+		      if (search_regs.start[c - '0'] >= 0
+			  && c <= search_regs.num_regs + '0')
 			{
 			  substart = search_regs.start[c - '0'];
 			  subend = search_regs.end[c - '0'];
 			}
+		      else
+			{
+			  /* If that subexp did not match,
+			     replace \\N with nothing.  */
+			  substart = 0;
+			  subend = 0;
+			}
 		    }
 		  else if (c == '\\')
 		    delbackslash = 1;