From 18e163fd3455deaa30b1effd19f51a5094bc0885 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sat, 3 Aug 2019 16:00:20 +0200 Subject: [PATCH] Fix error message in replace-match for subexpressions * src/search.c (Freplace_match): Output a more understandable error message when replacing a subexpression (bug#19208). --- src/search.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/search.c b/src/search.c index 2fa8b277195..0e2ae059e81 100644 --- a/src/search.c +++ b/src/search.c @@ -2404,6 +2404,12 @@ since only regular expressions have distinguished subexpressions. */) args_out_of_range (subexp, make_fixnum (search_regs.num_regs)); } + /* Check whether the subexpression to replace is greater than the + number of subexpressions in the regexp. */ + if (sub > 0 && search_regs.start[sub] == -1) + args_out_of_range (build_string ("Attempt to replace regexp subexpression that doesn't exist"), + subexp); + /* Sanity check to see whether the text to replace is present in the buffer/string. */ if (NILP (string)) -- 2.39.2