Mercurial > hg > octave-lyh
diff liboctave/regexp.cc @ 14452:721be41ea988 stable
Stop segfault when using regular expressions with named capture buffers (bug #35683).
liboctave/regexp.cc (match): Check current match has a named buffer before assigning it.
DLD-FUNCTIONS/regexp.cc: Add %!test for mix of named and unnamed buffers.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 11 Mar 2012 13:43:00 -0700 |
parents | 72c96de7a403 |
children | c57f9c911053 b472596cd7b9 |
line wrap: on
line diff
--- a/liboctave/regexp.cc +++ b/liboctave/regexp.cc @@ -371,8 +371,21 @@ || ovector[2*i-1] != ovector[2*i+1]) { if (namecount > 0) - named_tokens(named_idx(i-pos_offset-1)) = - std::string (*(listptr+nidx[i-pos_offset-1])); + { + // FIXME: Should probably do this with a map() + // rather than a linear search. However, + // the number of captured, named expressions + // is usually pretty small (< 4) + for (int j = 0; j < namecount; j++) + { + if (nidx[j] == i) + { + named_tokens(named_idx(j)) = + std::string (*(listptr+i-pos_offset)); + break; + } + } + } tokens(pos_match++) = std::string (*(listptr+i)); }