[Ada] Prevent crash in Is_Reachable
authorBob Duff <duff@adacore.com>
Mon, 12 Aug 2019 09:01:20 +0000 (09:01 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Mon, 12 Aug 2019 09:01:20 +0000 (09:01 +0000)
This patch fixes a bug in Is_Reachable, which causes a crash when checks
are on.

2019-08-12  Bob Duff  <duff@adacore.com>

gcc/ada/

* libgnat/a-cbmutr.adb (Is_Reachable): Declare Idx to be of the
base subtype.  Clearly it makes no sense to loop "while Idx >=
0", if Idx is of a nonnegative subtype.

From-SVN: r274301

gcc/ada/ChangeLog
gcc/ada/libgnat/a-cbmutr.adb

index 97f3141..4922e46 100644 (file)
@@ -1,5 +1,11 @@
 2019-08-12  Bob Duff  <duff@adacore.com>
 
+       * libgnat/a-cbmutr.adb (Is_Reachable): Declare Idx to be of the
+       base subtype.  Clearly it makes no sense to loop "while Idx >=
+       0", if Idx is of a nonnegative subtype.
+
+2019-08-12  Bob Duff  <duff@adacore.com>
+
        * libgnat/a-tifiio.adb (Put_Scaled): Prevent AA from being
        negative, since Field is range 0 .. something.
 
index cdc2629..fb8585a 100644 (file)
@@ -1767,10 +1767,8 @@ package body Ada.Containers.Bounded_Multiway_Trees is
      (Container : Tree;
       From, To  : Count_Type) return Boolean
    is
-      Idx : Count_Type;
-
+      Idx : Count_Type'Base := From;
    begin
-      Idx := From;
       while Idx >= 0 loop
          if Idx = To then
             return True;