diff mbox series

[Ada] Prevent crash in Put_Scaled

Message ID 20190812090251.GA22658@adacore.com
State New
Headers show
Series [Ada] Prevent crash in Put_Scaled | expand

Commit Message

Pierre-Marie de Rodat Aug. 12, 2019, 9:02 a.m. UTC
This patch fixes a bug in Put_Scaled, which causes a crash when checks
are on.

Tested on x86_64-pc-linux-gnu, committed on trunk

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.
diff mbox series

Patch

--- gcc/ada/libgnat/a-tifiio.adb
+++ gcc/ada/libgnat/a-tifiio.adb
@@ -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);