SIGSEGV during "GetOptionValues(<Short>, <Long>);" .eg. GetOptionValues('r', ''), multible 'r'
Original Reporter info from Mantis: DaddelLinux
-
Reporter name: Klaus Wandel
Original Reporter info from Mantis: DaddelLinux
- Reporter name: Klaus Wandel
Description:
Made a simple Lazaru console program with parameterized program start.
Range checks activated.
&LtPos;ExeName> -h -r [&LtPos;n>] -f 'MyFile.pas' -r [&LtPos;n>]
Got an SIGSEGV during "GetOptionValues(&LtPos;Short>, &LtPos;Long>);" .eg. GetOptionValues('r', '')
CheckOptions works as expected.
After some search i found following messages:
https://forum.lazarus.freepascal.org/index.php?topic=43170.0
https://bugs.freepascal.org/view.php?id=34879
But I don't think the problem is really resolved. Therefore I looked for the error and made the following changes in CustApp:
Steps to reproduce:
Made a simple Lazaru console program with parameterized program start.
Range checks activated.
&LtPos;ExeName> -h -r [&LtPos;n>] -f 'MyFile.pas' -r [&LtPos;n>]
Look forward for my changes
Additional information:
function TCustomApplication.GetOptionValues(const C: Char; const S: String): TStringArray;
Var
I,Cnt : Integer;
B : Boolean;
begin
SetLength(Result,ParamCount);
Cnt:=0;
// Error to be corrected with next command line.
// Local variables are not initialized by -1!
// Example: Multible optional attributes ('r::')
I:=-1; // line must be inserted
Repeat
I:=FindOptionIndex(C,B,I);
If I<>-1 then
begin
Inc(Cnt);
Dec(I);
end;
Until I=-1;
Repeat
I:=FindOptionIndex(S,B,I);
If I<>-1 then
begin
Inc(Cnt);
Dec(I);
end;
Until I=-1;
SetLength(Result,Cnt);
Cnt:=0;
// I := -1; // no need
Repeat
I:=FindOptionIndex(C,B,I);
If (I<>-1) then
begin
Result[Cnt]:=GetOptionAtIndex(I,False);
Inc(Cnt);
Dec(i);
end;
Until (I=-1);
// I := -1; // no need
Repeat
I:=FindOptionIndex(S,B,I);
If I<>-1 then
begin
Result[Cnt]:=GetOptionAtIndex(I,True);
Inc(Cnt);
Dec(i);
end;
Until (I=-1);
end;
function TCustomApplication.GetOptionAtIndex(AIndex : Integer; IsLong: Boolean): String;
Var
P : Integer;
O : String;
begin
Result:='';
If (AIndex=-1) then
Exit;
If IsLong then
begin // Long options have form --option=value
O:=Params[AIndex];
P:=Pos('=',O);
If (P=0) then
P:=Length(O);
Delete(O,1,P);
Result:=O;
end
else
begin // short options have form '-o value'
If (AIndex<ParamCount) then
//if (Copy(Application.Params[AIndex + 1], 1, 1) <> '-') then
// Fixed inconsistency: OptionChar
if (Copy(Application.Params[AIndex + 1], 1, 1) <> OptionChar) then
Result:=Params[AIndex+1];
end;
end;
Mantis conversion info:
- Mantis ID: 36438
- OS: WIN 10
- OS Build: 64 bit
- Build: 62129
- Platform: Desktop
- Version: 2.0.6
- Fixed in version: 3.3.1
- Target version: 3.2.0