From: Richard M. Stallman Date: Tue, 27 Jan 2004 04:52:09 +0000 (+0000) Subject: (Freplace_match): Handle nonexistent back-references properly. X-Git-Tag: ttn-vms-21-2-B4~7818 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=5fbbc83b2b8aa7d2f13c72467b43c6c71d01f388;p=emacs.git (Freplace_match): Handle nonexistent back-references properly. --- diff --git a/src/search.c b/src/search.c index 020573b75a1..c60d68b9374 100644 --- a/src/search.c +++ b/src/search.c @@ -2366,13 +2366,21 @@ since only regular expressions have distinguished subexpressions. */) 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;