]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix incorrect lower bound presumption in gnatlink
authorRonan Desplanques <desplanques@adacore.com>
Fri, 12 Apr 2024 14:45:08 +0000 (16:45 +0200)
committerMarc Poulhiès <poulhies@adacore.com>
Mon, 10 Jun 2024 09:03:59 +0000 (11:03 +0200)
This patch fixes a subprogram in gnatlink that incorrectly assumed
that the strings it is passed as arguments all have a lower bound of
1.

gcc/ada/

* gnatlink.adb (Check_File_Name): Fix incorrect assumption.

gcc/ada/gnatlink.adb

index d00fd9e5af7de1b87d2a9234431bf17716035c62..1455412ef93484a3086117f662834ce804cee2fa 100644 (file)
@@ -42,6 +42,7 @@ with Types;
 
 with Ada.Command_Line; use Ada.Command_Line;
 with Ada.Exceptions;   use Ada.Exceptions;
+with Ada.Strings.Fixed;
 
 with System.OS_Lib; use System.OS_Lib;
 with System.CRTL;
@@ -1697,15 +1698,13 @@ begin
 
       procedure Check_File_Name (S : String) is
       begin
-         for J in 1 .. FN'Length - (S'Length - 1) loop
-            if FN (J .. J + (S'Length - 1)) = S then
-               Error_Msg
-                 ("warning: executable file name """ & Output_File_Name.all
-                  & """ contains substring """ & S & '"');
-               Error_Msg
-                 ("admin privileges may be required to run this file");
-            end if;
-         end loop;
+         if Ada.Strings.Fixed.Index (FN, S) /= 0 then
+            Error_Msg
+              ("warning: executable file name """ & Output_File_Name.all
+               & """ contains substring """ & S & '"');
+            Error_Msg
+              ("admin privileges may be required to run this file");
+         end if;
       end Check_File_Name;
 
    --  Start of processing for Bad_File_Names_On_Windows