BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: Indy 9.18: IdGlobal.PosIdx bug ?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock
View previous topic :: View next topic  
Author Message
ilya ovsishcher
Guest





PostPosted: Thu Jan 27, 2005 3:38 pm    Post subject: Re: Indy 9.18: IdGlobal.PosIdx bug ? Reply with quote




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


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.