]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Guard agains empty switches in GNAT.Command_Line.Getopt
authorViljar Indus <indus@adacore.com>
Thu, 14 May 2026 12:05:21 +0000 (15:05 +0300)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 4 Jun 2026 08:42:18 +0000 (10:42 +0200)
Checks for the first character in Switches being an '*'
did not include guards against an empty string in all locations.

gcc/ada/ChangeLog:

* libgnat/g-comlin.adb (Getopt): Check if Switches
are empty before looking at the first element.

gcc/ada/libgnat/g-comlin.adb

index 18905cc135e67d148755a79e423f427dcdcbcf48..ad7835733ca317604af558b02df58584e99ef050 100644 (file)
@@ -666,7 +666,7 @@ package body GNAT.Command_Line is
                --  isn't the parameter to a previous switch, since that has
                --  already been handled.
 
-               if Switches (Switches'First) = '*' then
+               if Switches /= "" and then Switches (Switches'First) = '*' then
                   Set_Parameter
                     (Parser.The_Switch,
                      Arg_Num => Parser.Current_Argument,
@@ -901,7 +901,8 @@ package body GNAT.Command_Line is
                   --  If Concatenate is False and the full argument is not
                   --  recognized as a switch, this is an invalid switch.
 
-                  if Switches (Switches'First) = '*' then
+                  if Switches /= "" and then Switches (Switches'First) = '*'
+                  then
                      Set_Parameter
                        (Parser.The_Switch,
                         Arg_Num => Parser.Current_Argument,