]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix incorrect String lower bound in gnatlink
authorRonan Desplanques <desplanques@adacore.com>
Wed, 24 Apr 2024 08:18:13 +0000 (10:18 +0200)
committerMarc Poulhiès <poulhies@adacore.com>
Thu, 13 Jun 2024 13:30:29 +0000 (15:30 +0200)
This patch fixes code in gnatlink that incorrectly assumed that the
lower bound of a particular string was always 1.

gcc/ada/

* gnatlink.adb (Gnatlink): Fix incorrect lower bound assumption.
(Is_Prefix): New function.

gcc/ada/gnatlink.adb

index 1455412ef93484a3086117f662834ce804cee2fa..db0fd144a13e420ad7e0818673431528e2b9374e 100644 (file)
@@ -1885,6 +1885,24 @@ begin
          Shared_Libgcc_Seen : Boolean := False;
          Static_Libgcc_Seen : Boolean := False;
 
+         function Is_Prefix
+           (Complete_String : String; Prefix : String) return Boolean;
+         --  Returns whether Prefix is a prefix of Complete_String
+
+         ---------------
+         -- Is_Prefix --
+         ---------------
+
+         function Is_Prefix
+           (Complete_String : String; Prefix : String) return Boolean
+         is
+            S : String renames Complete_String;
+            P : String renames Prefix;
+         begin
+            return P'Length <= S'Length
+              and then S (S'First .. S'First + P'Length - 1) = P;
+         end Is_Prefix;
+
       begin
          J := Linker_Options.First;
          while J <= Linker_Options.Last loop
@@ -1936,13 +1954,12 @@ begin
             --  Here we just check for a canonical form that matches the
             --  pragma Linker_Options set in the NT runtime.
 
-            if (Linker_Options.Table (J)'Length > 17
-                and then Linker_Options.Table (J) (1 .. 17) =
-                  "-Xlinker --stack=")
-              or else
-                (Linker_Options.Table (J)'Length > 12
-                 and then Linker_Options.Table (J) (1 .. 12) =
-                       "-Wl,--stack=")
+            if Is_Prefix
+                 (Complete_String => Linker_Options.Table (J).all,
+                  Prefix => "-Xlinker --stack=")
+              or else Is_Prefix
+                        (Complete_String => Linker_Options.Table (J).all,
+                         Prefix => "-Wl,--stack=")
             then
                if Stack_Op then
                   Linker_Options.Table (J .. Linker_Options.Last - 1) :=