https://gcc.gnu.org/g:36dc851484949c2e5d4fbfe33b8b336699a46104

commit r16-4683-g36dc851484949c2e5d4fbfe33b8b336699a46104
Author: Denis Mazzucato <[email protected]>
Date:   Tue Sep 23 17:38:52 2025 +0200

    ada: Fix crash when an invalid warning switch contains trailing spaces
    
    This patch fixes the crash that happens when emitting the error message of 
an
    invalid warning switch with trailing spaces.
    
    gcc/ada/ChangeLog:
    
            * sem_prag.adb (Analyze_Pragma): Add enclosing quotation when the
            invalid switch ends with a space.

Diff:
---
 gcc/ada/sem_prag.adb | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index 6b38de037bf9..59c1976dbe97 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -28770,6 +28770,17 @@ package body Sem_Prag is
                         OK  : Boolean;
                         Chr : Character;
 
+                        function Enclose_Ending_Space
+                           (Raw_Str : String) return String
+                        is (if Raw_Str (Raw_Str'Last) = ' '
+                              then '"' & Raw_Str & '"'
+                              else Raw_Str);
+                        function Enclose_Ending_Space
+                           (Raw_Chr : Character) return String
+                        is (Enclose_Ending_Space ((1 => Raw_Chr)));
+                        --  This function ensures that no error message ends
+                        --  with a space, in case we enclose it within quotes.
+
                      begin
                         J := 1;
                         while J <= Len loop
@@ -28801,7 +28812,8 @@ package body Sem_Prag is
                                  if not Set_Warning_Switch ('.', Chr) then
                                     Error_Pragma_Arg
                                       ("invalid warning switch character "
-                                       & '.' & Chr, Arg1);
+                                       & Enclose_Ending_Space ('.' & Chr),
+                                       Arg1);
                                  end if;
 
                               --  Non-Dot case
@@ -28812,7 +28824,8 @@ package body Sem_Prag is
 
                               if not OK then
                                  Error_Pragma_Arg
-                                   ("invalid warning switch character " & Chr,
+                                   ("invalid warning switch character "
+                                    & Enclose_Ending_Space (Chr),
                                     Arg1);
                               end if;

Reply via email to