ilya ovsishcher Guest
|
Posted: Thu Jan 27, 2005 3:38 pm Post subject: Re: Indy 9.18: IdGlobal.PosIdx bug ? |
|
|
From: "ilya ovsischer" <iomongol (AT) popa (DOT) com>
Subject: Indy 9.18: IdGlobal.PosIdx bug ?
Date: Wednesday, January 26, 2005 1:29 PM
Story: POP3 component was returning Access Violation while geting one
particular email (POP.Retrieve).
I went as deep as I can and find out that issue is in PosIdx. Check comments
and changes below. Now I have compiler warning, but application doesn' fail
and capable of downloading email the same way as Outlook Express or any
other tool. Please let me know if it is a bug and if yes, please spank coder
a few times.
Function PosIdx (const ASubStr,AStr: AnsiString; AStartPos: cardinal):
Cardinal;
var
lpSubStr,lpS: PChar;
//IO was LenSubStr,LenS: cardinal;
//IO changed to longint, below Dec(LenS) done. if LenS=0 and Dec is done
it will be huge positive number = Access Violation guaranteed
LenSubStr,LenS: longint;
LChar: Char;
Begin
Result := 0; //not found
LenSubStr := Length(ASubStr);
LenS := Length(AStr);
if (LenSubStr = 0) or (LenSubStr > LenS) or (AStartPos > LenS) then begin
Exit;
end;//if
lpSubStr := Pointer(ASubStr);
lpS := Pointer(AStr);
if AStartPos > 1 then begin
Inc(lpS, AStartPos - 1);
Dec(LenS, AStartPos - 1);
end;//if
if LenS <= 0 then begin
Exit;
end;
LChar := lpSubStr[0]; //first char
Inc(lpSubStr); //next char
Dec(LenSubStr); //len w/o first char
Dec(LenS, LenSubStr); //Length(S)-Length(SubStr) +1(!) MUST BE >0
if LenS <= 0 then begin
Exit;
end;//if
// RLebeau - shouldn't this code use StrPos() instead?
while LenS > 0 do begin
if lpS^ = LChar then begin
Inc(lpS);
if CompareMem(lpS, lpSubStr, LenSubStr) then begin
Result := lpS-Pointer(AStr); //+1 already here
Exit;
end;
end else begin
Inc(lpS);
end;
Dec(LenS);
end;//while
End;//PosIdx
|
|