[fpc-pascal]Strange Segfault...
James Mills
prologic at daisy.ods.org
Thu Jul 10 15:53:22 CEST 2003
(gdb) break 14
Breakpoint 1 at $806603c: file test4.pas, line 14.
(gdb) run
Starting program: /home/pircsrv/src/test4
Enter a string: Abernus!SiLenT2003 at ProLogiTech.NET.au
Replace all digits with ?
Breakpoint 1, main () at test4.pas:14
14 readLn(w);
(gdb) n
X
15 replace(['0'..'9'], w, s);
(gdb) s
Program received signal SIGSEGV, Segmentation fault.
$08066073 in main () at test4.pas:15
15 replace(['0'..'9'], w, s);
(gdb)
Can anyone help me find out what's going on here ?
It doesn't even go into the function and just segfaults! Makes me think
FPC can't handle the ['0'..'9'] passed to the function...
replace is defined as such:
procedure replace(search: String; replace: String; var s: String);
procedure replace(const chars: array of char; replace: String; var s: String);
procedure replace(search: String; replace: String; var s: String);
var
startPos: Integer;
done: Boolean;
begin
done := FALSE;
while NOT done do
begin
startPos := pos(search, s);
if (startPos = 0) then
begin
done := TRUE;
end
else
begin
delete(s, startPos, length(search));
insert(replace, s, startPos);
end;
end;
end;
procedure replace(const chars: array of char; replace: String; var s: String);
var
index: Integer;
done: Boolean;
begin
done := FALSE;
while NOT done do
begin
if NOT isin(s, chars, index) then
begin
done := TRUE;
end
else
begin
delete(s, index, 1);
insert(replace, s, index);
end;
end;
end;
the isin functions are defined as such:
function isin(s: String; search: String): Boolean;
function isin(s: String; const chars: array of char): Boolean;
function isin(s: String; const chars: array of char; var index: Integer): Boolean;
function isin(s: String; search: String): Boolean;
begin
if pos(search, s) = 0 then
begin
isin := FALSE;
end
else
begin
isin := TRUE;
end
end;
function isin(s: String; const chars: array of char): Boolean;
var
i: Integer;
begin
isin := isin(s, chars, i);
end;
function isin(s: String; const chars: array of char; var index: Integer): Boolean;
var
i: Integer;
begin
isin := TRUE;
for i := low(chars) to high(chars) do
begin
if NOT isin(s, '' + chars[i]) then
begin
index := i;
isin := FALSE;
break;
end;
end;
end;
Anything would be helpfull :)
cheers
James
--
-
- James Mills
Zero Defect Software Engineers Group - ZDSEG
More information about the fpc-pascal
mailing list