From fc6e52e5158d0738d302eb39f6b5d709b03683a8 Mon Sep 17 00:00:00 2001 From: mattias Date: Wed, 26 Mar 2008 17:52:58 +0000 Subject: [PATCH] codetools: h2p: added safety check git-svn-id: trunk@14660 - --- components/codetools/nonpascalcodetools.pas | 42 +++++++++++---------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/components/codetools/nonpascalcodetools.pas b/components/codetools/nonpascalcodetools.pas index d2c538d095..dd737fede4 100644 --- a/components/codetools/nonpascalcodetools.pas +++ b/components/codetools/nonpascalcodetools.pas @@ -410,28 +410,32 @@ begin {$R-} Result:=Source; DstPos:=1; - SrcPos:=1; + SrcPos:=StartPos; SrcLen:=length(Source); if EndPos<1 then EndPos:=SrcLen+1; - if SrcLen>EndPos then SrcLen:=EndPos; - repeat - ReadRawNextCAtom(Source,SrcPos,AtomStart); - if AtomStart>=EndPos then break; - if not (Source[AtomStart] in [#10,#13]) then begin - if IsIdentChar[Source[AtomStart]] - and ((DstPos=1) or (IsIdentChar[Result[DstPos-1]])) then begin - // space needed between words/numbers - Result[DstPos]:=' '; - inc(DstPos); + if EndPos>SrcLen then EndPos:=SrcLen+1; + if SrcPos=EndPos then break; + if not (Source[AtomStart] in [#10,#13]) then begin + if IsIdentChar[Source[AtomStart]] + and ((DstPos=1) or (IsIdentChar[Result[DstPos-1]])) then begin + // space needed between words/numbers + Result[DstPos]:=' '; + inc(DstPos); + end; + // copy word + while AtomStartlength(Result)+1 then + raise Exception.Create(''); SetLength(Result,DstPos-1); {$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF} end;