TRegexEngine.MatchString causes segfault
Original Reporter info from Mantis: sethdgrover@gmail.com
-
Reporter name: Seth Grover
Original Reporter info from Mantis: sethdgrover@gmail.com
- Reporter name: Seth Grover
Description:
When I run the included sample program with these parameters (see "Steps To Reproduce"), my TRegexEngine object generates an access violation.
Here's the stack trace:
Program received signal SIGSEGV, Segmentation fault.
TREGEXENGINE__RCMATCHSUBSTRING (S=0xb7f02158 'ascii_lf1', STARTPOSN=-885697656, LEN=Cannot access memory at address 0xcb355388
) at regex.pp:625
Current language: auto; currently pascal
(gdb) bt
#0 TREGEXENGINE__RCMATCHSUBSTRING (S=0xb7f02158 'ascii_lf1', STARTPOSN=-885697656, LEN=Cannot access memory at address 0xcb355388
) at regex.pp:625
#1 0x08061e75 in TREGEXENGINE__MATCHSTRING (S=0xb7f02158 'ascii_lf1', MATCHPOS=Cannot access memory at address 0xcb355388
) at regex.pp:307
#2 0x08048499 in main () at project1.lpr:27
There's not a lot of examples on how to use this, but from what I can tell I'm doing it right and it shouldn't segfault.
Steps to reproduce:
Here's a sample program, run:
./project1 'as.*0' 'ascii_lf1'
to cause the crash
program project1;
// Run the following to cause an access violation
//
// ./project1 'as.*0' 'ascii_lf1'
//
{$mode objfpc}{$H+}
uses
regex,
SysUtils;
var
re : TRegexEngine;
aErrorPos : integer;
aErrorCode: TRegexError;
MatchPos : integer;
Offset : integer;
begin
try
WriteLn('Regex: Trim(ParamStr(1)) = >>'+Trim(ParamStr(1))+'<<');
WriteLn('Test: Trim(ParamStr(2)) = >>'+Trim(ParamStr(2))+'<<');
re := TRegexEngine.Create(Trim(ParamStr(1)));
if re.Parse(aErrorPos,aErrorCode) then begin
Offset := 1;
if re.MatchString(ParamStr(2),MatchPos,Offset) then begin
WriteLn('Match');
end else begin
WriteLn('No Match');
end;
end else begin
WriteLn('Parse Failed');
end;
except
on E : Exception do begin
WriteLn('Exception: '+E.Message);
end;
end;
end.
Mantis conversion info:
- Mantis ID: 14236
- OS: Ubuntu
- OS Build: 9.04 (2.6.28-13)
- Build: from 2.2.4 svn rev 13097
- Platform: x68 Linux
- Version: 2.2.4
- Fixed in revision: 13521 (#e9b5bcc1)