Import Editor Macros - Index out of range (-1)
Original Reporter info from Mantis: serbod
-
Reporter name:
Original Reporter info from Mantis: serbod
- Reporter name:
Description:
When importing editor macros from XML file, "Index out of range (-1)" error occured
Additional information:
==== Faulty code:
function TIdeMacroEventReader.PosToXY: TPoint;
var
f: TStringList;
begin
f := TStringList.Create;
f.Text := copy(FOrigText,1 ,FPos);
Result.y := f.Count;
Result.x := length(f[f.Count-1])+1; // <<< when f.Count = 0
f.Free;
end;
==== Call stack:
#0 fpc_raiseexception at :0
#1 CLASSES$_$TSTRINGS_$__$$_ERROR$ANSISTRING$LONGINT at :0
#2 CLASSES$_$TSTRINGLIST_$__$$_CHECKINDEX$LONGINT at :0
#3 CLASSES$_$TSTRINGLIST_$__$$_GET$LONGINT$$ANSISTRING at :0
#4 POSTOXY(0x733fb40) at editormacrolistviewer.pas:796
#5 ADDERROR(0x733fb40, 0x8a38598 'Unknown Command "procedur'...) at editormacrolistviewer.pas:804
#6 PARSENEXTEVENT(0x733fb40) at editormacrolistviewer.pas:877
#7 SETFROMSOURCE(0x733f780, 0x6d33d78 'procedure FindNextSelecte'...) at editormacrolistviewer.pas:692
#8 READFROMXMLCONF(0x733f780, 0x12e35f0, 0x1013e0960 'EditorMacros/Macro1/') at editormacrolistviewer.pas:723
#9 MNIMPORTCLICK(0x79cd990, 0x6f97c10) at editormacrolistviewer.pas:1243
==== Suggested fix:
function TIdeMacroEventReader.PosToXY: TPoint;
var
f: TStringList;
begin
f := TStringList.Create;
try
f.Text := Copy(FOrigText, 1, FPos);
Result.y := f.Count;
if f.Count > 0 then
Result.x := Length(f[f.Count-1]) + 1
else
Result.x := 0;
finally
f.Free;
end;
end;
==== Also faulty function:
function TIdeMacroEventReader.ParseNextEvent: Boolean;
procedure SkipNum(var i: integer);
begin
while (i <= Length(FText)) and (FText[i] in ['0'..'9']) do inc (i);
end;
procedure SkipSpace(var i: integer);
begin
while (i <= Length(FText)) and (FText[i] in [' '..#9, #13, #10]) do inc (i); // <<< ' '..#9 range treated as empty range with warning!
end;
Mantis conversion info:
- Mantis ID: 36082
- Build: 61897
- Fixed in version: 2.0.6
- Fixed in revision: 61898 (#ad89fb55)
- Target version: 2.0.6