aboutsummaryrefslogtreecommitdiffstats
path: root/src/expr.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2021-01-26 09:23:54 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2021-01-26 09:24:41 -0800
commit735083ba24878075235007b4417982ad5700436d (patch)
tree9b29545fd8b7a6b0c31322e64c58321f1bb4cb94 /src/expr.c
parentsplit: fix --number=K/N to output correct part of file (diff)
downloadcoreutils-735083ba24878075235007b4417982ad5700436d.tar.gz
coreutils-735083ba24878075235007b4417982ad5700436d.zip
expr: fix bug with unmatched \(...\)
Problem reported by Qiuhao Li. * NEWS: Mention this. * doc/coreutils.texi (String expressions): Document the correct behavior, which POSIX requires. * src/expr.c (docolon): Treat unmatched \(...\) as empty. * tests/misc/expr.pl: New test.
Diffstat (limited to 'src/expr.c')
-rw-r--r--src/expr.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/expr.c b/src/expr.c
index afd8b9ca5..4893d948f 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -614,8 +614,13 @@ docolon (VALUE *sv, VALUE *pv)
/* Were \(...\) used? */
if (re_buffer.re_nsub > 0)
{
- sv->u.s[re_regs.end[1]] = '\0';
- v = str_value (sv->u.s + re_regs.start[1]);
+ if (re_regs.end[1] < 0)
+ v = str_value ("");
+ else
+ {
+ sv->u.s[re_regs.end[1]] = '\0';
+ v = str_value (sv->u.s + re_regs.start[1]);
+ }
}
else
{