Sun 11 Mar 2012 06:03:04 PM UTC, comment #3:
Interestingly, my system does not behave the same as yours and I don't see segfaults for your reduced testcases. This is probably due to subtle differences in the way things are laid out in memory. I'm sure the memory corruption is occurring, but it doesn't always lead to an actual segfault.
The following string and pattern combination always segfaults for me (tested on versions 3.2.4, 3.4.0, 3.4.3, 3.6.1, and the dev).
The problem seems to be with the mixing of named and unnamed match buffers. The outer parentheses in the pattern above create a match buffer, which happens to be named label. The inner parenthesis, which I know you are intending to use only for grouping, also creates an unnamed match buffer. When you ask for the named match tokens Octave indexes into an array of names. It finds the first name, <label>, but when it goes to find the second name it oversteps the array bounds.
A solution in this case is to use alternation without creating a back reference. The syntax for this is '(?:A|B)'. While the example above segfaults, this one works.
Another possibility is to explicitly name every capture backreference. I tried that with your original pattern and it no longer segfaults. (I don't think it's giving you what you want but that is a different question about what the regexp should be picking out from the string.)
The pattern that doesn't segfault is
Where I have used 'unname1' and 'unname2' for the previously implicit capture buffers.
Obviously, there is still a deeper problem that bad input, no matter how malformed, shouldn't cause the program to segfault. It should produce a warning or error message and return to the prompt.
|