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

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

gcc/ada/

* libgnat/a-tifiio.adb (Put_Scaled): Prevent AA from being
negative, since Field is range 0 .. something.

From-SVN: r274300

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

index 1bf7e6d..97f3141 100644 (file)
@@ -1,5 +1,10 @@
 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.
+
+2019-08-12  Bob Duff  <duff@adacore.com>
+
        * doc/gnat_ugn/gnat_utility_programs.rst (gnatmetric, gnatpp,
        gnatstub): Remove documentation for Ada language version
        switches, and note that they are no longer needed.
index 1c817ea..d048646 100644 (file)
@@ -560,7 +560,7 @@ package body Ada.Text_IO.Fixed_IO is
          E       : Integer)
       is
          pragma Assert (E >= -Max_Digits);
-         AA : constant Field := E + A;
+         AA : constant Field := Integer'Max (E + A, 0);
          N  : constant Natural := (AA + Max_Digits - 1) / Max_Digits + 1;
 
          Q  : array (0 .. N - 1) of Int64 := (others => 0);