[go: up one dir, main page]

Menu

#9 List index out of bounds (TUIBSQLParser.GetStatement)

open
nobody
None
5
2016-04-28
2013-03-06
Anonymous
No

In the function TUIBSQLParser.GetStatement there is an error in a cycle condition.
The FLine variable is equal to FStrings.Count, not FStrings.Count - 1.

How to fix:
Add a new variable

EndLine = FLine - 1

and to use it instead of FLine.

Source code (before fix):

<code>
function TUIBSQLParser.GetStatement: string;
var
i: integer;
str: string;
begin
result := '';
for i := FMarkerLine to FLine do
begin
str := FStrings[i];
if (FMarkerLine = FLine) then
Result := copy(str, FMarkerPos +1, FCursor - PChar(FStr) - FMarkerPos ) else
if (FMarkerLine = i) then
Result := copy(str, FMarkerPos + 1, Length(Str) - FMarkerPos) else
if i <> FLine then
Result := Result + #13#10 + str else
Result := Result + #13#10 + copy(str, 0, FCursor - PChar(FStr))
end;
end;
</code>

Result code (after fix):

<code>
function TUIBSQLParser.GetStatement: string;
var
i: integer;
str: string;
EndLine: Integer;
begin
result := '';
EndLine := FLine - 1;
for i := FMarkerLine to EndLine do
begin
str := FStrings[i];
if (FMarkerLine = EndLine) then
Result := copy(str, FMarkerPos +1, FCursor - PChar(FStr) - FMarkerPos ) else
if (FMarkerLine = i) then
Result := copy(str, FMarkerPos + 1, Length(Str) - FMarkerPos) else
if i <> EndLine then
Result := Result + #13#10 + str else
Result := Result + #13#10 + copy(str, 0, FCursor - PChar(FStr))
end;
end;
</code>

Discussion

  • adem0x

    adem0x - 2013-09-15

    This has not been applied to SVN trunk as yet (see the date of this post); could someone do that please.

     
  • Askhat Kairov

    Askhat Kairov - 2014-04-22

    This is my ticket (I registered again).

     

Log in to post a comment.