View Issue Details

IDProjectCategoryView StatusLast Update
0036438FPCLCLpublic2019-12-14 13:00
ReporterKlaus WandelAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformDesktopOSWIN 10OS Version64 bit
Product VersionProduct Build62129 
Target VersionFixed in Version3.3.1 
Summary0036438: SIGSEGV during "GetOptionValues(<Short>, <Long>);" .eg. GetOptionValues('r', ''), multible 'r'
DescriptionMade a simple Lazaru console program with parameterized program start.
Range checks activated.
<ExeName> -h -r [<n>] -f 'MyFile.pas' -r [<n>]
Got an SIGSEGV during "GetOptionValues(<Short>, <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 ReproduceMade a simple Lazaru console program with parameterized program start.
Range checks activated.
<ExeName> -h -r [<n>] -f 'MyFile.pas' -r [<n>]
Look forward for my changes
Additional Informationfunction 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;
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget3.2.0
Attached Files

Activities

Michael Van Canneyt

2019-12-14 12:52

administrator   ~0119833

The extra line is already there in trunk. You need to wait till the next FPC release 3.2

Michael Van Canneyt

2019-12-14 13:00

administrator   ~0119835

PS. Changed the option char test in GetOptionAtIndex, rev. 43680.

Issue History

Date Modified Username Field Change
2019-12-14 12:14 Klaus Wandel New Issue
2019-12-14 12:47 Michael Van Canneyt Assigned To => Michael Van Canneyt
2019-12-14 12:47 Michael Van Canneyt Status new => assigned
2019-12-14 12:47 Michael Van Canneyt Project Lazarus => FPC
2019-12-14 12:52 Michael Van Canneyt Status assigned => resolved
2019-12-14 12:52 Michael Van Canneyt Resolution open => fixed
2019-12-14 12:52 Michael Van Canneyt Fixed in Version => 3.3.1
2019-12-14 12:52 Michael Van Canneyt FPCTarget => 3.2.0
2019-12-14 12:52 Michael Van Canneyt Note Added: 0119833
2019-12-14 13:00 Michael Van Canneyt Note Added: 0119835