Bug found in TstringList
From: Skybuck Flying (nospam_at_hotmail.com)
Date: 11/22/04
- Next message: Skybuck Flying: "Re: OO problem: How to create a duplicate of a derived class with only a base variable ?"
- Previous message: J French: "Re: HTML viewer feedback on"
- Next in thread: Jim P: "Re: Bug found in TstringList"
- Reply: Jim P: "Re: Bug found in TstringList"
- Reply: Jamie: "Re: Bug found in TstringList"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 22 Nov 2004 10:59:38 +0100
Hi,
I tried to read this file that contained a char(0) at the beginning of the
file.
TStringList tries to split up the string that it loaded into multiple
strings with SetTextStr
This method is flawed since it simply exists on the first character being 0
and ignores the rest of the text !
( while it should ofcourse have processed the rest of the text ! )
That's the bug ;)
procedure TStrings.SetTextStr(const Value: string);
var
P, Start: PChar;
S: string;
begin
BeginUpdate;
try
Clear;
P := Pointer(Value);
if P <> nil then
while P^ <> #0 do // bug
begin
Start := P;
while not (P^ in [#0, #10, #13]) do Inc(P);
SetString(S, Start, P - Start);
Add(S);
if P^ = #13 then Inc(P);
if P^ = #10 then Inc(P);
end;
finally
EndUpdate;
end;
end;
/\
|
|
procedure TStrings.LoadFromStream(Stream: TStream);
var
Size: Integer;
S: string;
begin
BeginUpdate;
try
Size := Stream.Size - Stream.Position;
SetString(S, nil, Size);
Stream.Read(Pointer(S)^, Size);
SetTextStr(S); // goes to bug
finally
EndUpdate;
end;
end;
/\
|
|
procedure TStrings.LoadFromFile(const FileName: string);
var
Stream: TStream;
begin
Stream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
try
LoadFromStream(Stream); // goes to bug
finally
Stream.Free;
end;
end;
Bye,
Skybuck.
- Next message: Skybuck Flying: "Re: OO problem: How to create a duplicate of a derived class with only a base variable ?"
- Previous message: J French: "Re: HTML viewer feedback on"
- Next in thread: Jim P: "Re: Bug found in TstringList"
- Reply: Jim P: "Re: Bug found in TstringList"
- Reply: Jamie: "Re: Bug found in TstringList"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|