changeset 13759:c4b6ea833fa5

Fix infinite loop with null patterns in regexp (Bug #34101, Bug #33258) * regexp.cc: For zero length matches, move to next character and keep processing unless end of string is reached.
author Rik <octave@nomad.inbox5.com>
date Wed, 26 Oct 2011 21:23:32 -0700
parents 9586dc4e838b
children 1d97688f8522
files src/DLD-FUNCTIONS/regexp.cc
diffstat 1 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/DLD-FUNCTIONS/regexp.cc	Wed Oct 26 22:33:27 2011 -0400
+++ b/src/DLD-FUNCTIONS/regexp.cc	Wed Oct 26 21:23:32 2011 -0700
@@ -422,9 +422,12 @@
             break;
           else if (ovector[1] <= ovector[0])
             {
-              // FIXME: Zero sized match!! Is this the right thing to do?
+              // Zero sized match.  Skip to next char.
               idx = ovector[0] + 1;
-              continue;
+              if (idx < buffer.length ())
+                continue;
+              else
+                break;
             }
           else
             {
@@ -1040,6 +1043,8 @@
 
 ## seg-fault test
 %!assert(regexp("abcde","."),[1,2,3,4,5])
+## Infinite loop test
+%!assert (isempty (regexp("abcde", "")))
 
 ## Check that anchoring of pattern works correctly
 %!assert(regexp('abcabc','^abc'),1);