From: Viljar Indus <[email protected]>

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.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/libgnat/g-comlin.adb | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/libgnat/g-comlin.adb b/gcc/ada/libgnat/g-comlin.adb
index 18905cc135e..ad7835733ca 100644
--- a/gcc/ada/libgnat/g-comlin.adb
+++ b/gcc/ada/libgnat/g-comlin.adb
@@ -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,
-- 
2.53.0

Reply via email to