aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS5
-rw-r--r--src/ptx.c5
-rwxr-xr-xtests/misc/ptx.pl6
3 files changed, 16 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 8be22f169..ca36063eb 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,11 @@ GNU coreutils NEWS -*- outline -*-
* Noteworthy changes in release ?.? (????-??-??) [?]
+** Bug fixes
+
+ ptx -S no longer infloops for a pattern which returns zero-length matches.
+ [the bug dates back to the initial implementation]
+
* Noteworthy changes in release 8.28 (2017-09-01) [stable]
diff --git a/src/ptx.c b/src/ptx.c
index 2aababff6..b7aa1079b 100644
--- a/src/ptx.c
+++ b/src/ptx.c
@@ -818,6 +818,11 @@ find_occurs_in_text (int file_index)
case -1:
break;
+ case 0:
+ die (EXIT_FAILURE, 0,
+ _("error: regular expression has a match of length zero: %s"),
+ quote (context_regex.string));
+
default:
next_context_start = cursor + context_regs.end[0];
break;
diff --git a/tests/misc/ptx.pl b/tests/misc/ptx.pl
index d71d06500..4d4e1c729 100755
--- a/tests/misc/ptx.pl
+++ b/tests/misc/ptx.pl
@@ -40,6 +40,12 @@ my @Tests =
{OUT=>".xx \"\" \"\" \"foo\" \"\"\n"}],
["format-t", '--format=tex', {IN=>"foo\n"},
{OUT=>"\\xx {}{}{foo}{}{}\n"}],
+
+# with coreutils-8.28 and earlier, the -S option would infloop with
+# matches of zero-length.
+["S-infloop", '-S ^', {IN=>"a\n"}, {EXIT=>1},
+ {ERR_SUBST=>'s/^.*reg.*ex.*length zero.*$/regexlzero/'},
+ {ERR=>"regexlzero\n"}],
);
@Tests = triple_test \@Tests;