Patchwork [Ada] Handling of -vPx with incorrect x

login
register
mail settings
Submitter Arnaud Charlet
Date Oct. 1, 2012, 8:20 a.m.
Message ID <20121001082040.GA24257@adacore.com>
Download mbox | patch
Permalink /patch/188235/
State New
Headers show

Comments

Arnaud Charlet - Oct. 1, 2012, 8:20 a.m.
Command line switch -vPx (set verbosity level for project file facility) in
gnatmake and gnatcmd is is valid only for x=0, 1, or 2. This change ensures
that any attempt to pass an invalid value generates a proper error message.

The following commands must generate the indicated errors:

$ gnat list -vP9 -Pinvalid_verbosity_prj invalid_verbosity_proc.adb
gnat: invalid verbosity level: 9

$ gnat compile -q -vP9 -Pinvalid_verbosity_prj invalid_verbosity_proc.adb
gnatmake: invalid verbosity level 9

$ gnatmake -q -vP9 -Pinvalid_verbosity_prj invalid_verbosity_proc.adb
gnatmake: invalid verbosity level 9

project invalid_verbosity_prj is end invalid_verbosity_prj;

procedure invalid_verbosity_proc is end invalid_verbosity_proc;

Tested on x86_64-pc-linux-gnu, committed on trunk

2012-10-01  Thomas Quinot  <quinot@adacore.com>

	* gnatcmd.adb, make.adb (Scan_Make_Arg, Inspect_Switches): Recognize
	and reject an invalid parameter passed to -vP.

Patch

Index: gnatcmd.adb
===================================================================
--- gnatcmd.adb	(revision 191888)
+++ gnatcmd.adb	(working copy)
@@ -1769,20 +1769,28 @@ 
 
                   --  -vPx  Specify verbosity while parsing project files
 
-                  elsif Argv'Length = 4
-                    and then Argv (Argv'First + 1 .. Argv'First + 2) = "vP"
-                  then
-                     case Argv (Argv'Last) is
-                        when '0' =>
-                           Current_Verbosity := Prj.Default;
-                        when '1' =>
-                           Current_Verbosity := Prj.Medium;
-                        when '2' =>
-                           Current_Verbosity := Prj.High;
-                        when others =>
-                           Fail ("Invalid switch: " & Argv.all);
-                     end case;
+                  elsif Argv (Argv'First + 1 .. Argv'First + 2) = "vP" then
+                     if Argv'Length = 4
+                          and then Argv (Argv'Last) in '0' .. '2'
+                     then
+                        case Argv (Argv'Last) is
+                           when '0' =>
+                              Current_Verbosity := Prj.Default;
+                           when '1' =>
+                              Current_Verbosity := Prj.Medium;
+                           when '2' =>
+                              Current_Verbosity := Prj.High;
+                           when others =>
 
+                              --  Cannot happen
+
+                              raise Program_Error;
+                        end case;
+                     else
+                        Fail ("invalid verbosity level: "
+                                & Argv (Argv'First + 3 .. Argv'Last));
+                     end if;
+
                      Remove_Switch (Arg_Num);
 
                   --  -Pproject_file  Specify project file to be used
Index: make.adb
===================================================================
--- make.adb	(revision 191890)
+++ make.adb	(working copy)
@@ -7825,11 +7825,12 @@ 
 
          --  -vPx  (verbosity of the parsing of the project files)
 
-         elsif Argv'Last = 4
-           and then Argv (2 .. 3) = "vP"
-           and then Argv (4) in '0' .. '2'
-         then
-            if And_Save then
+         elsif Argv (2 .. 3) = "vP" then
+            if Argv'Last /= 4 or else Argv (4) not in '0' .. '2' then
+               Make_Failed
+                 ("invalid verbosity level " & Argv (4 .. Argv'Last));
+
+            elsif And_Save then
                case Argv (4) is
                   when '0' =>
                      Current_Verbosity := Prj.Default;