diff mbox

[Ada] Fix thinko in bignum allocation routine

Message ID 20121029113402.GA31398@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Oct. 29, 2012, 11:34 a.m. UTC
This makes the new support for extended overflow checking work on big-endian
platforms as well by fixing a thinko in the allocation routine of bignums.

No functional changes.

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

2012-10-29  Eric Botcazou  <ebotcazou@adacore.com>

	* s-bignum.adb (Allocate_Bignum): Use the exact layout of
	Bignum_Data for the overlay.
diff mbox

Patch

Index: s-bignum.adb
===================================================================
--- s-bignum.adb	(revision 192933)
+++ s-bignum.adb	(working copy)
@@ -233,14 +233,27 @@ 
             pragma Import (Ada, BD);
 
             --  Expose a writable view of discriminant BD.Len so that we can
-            --  initialize it.
+            --  initialize it. We need to use the exact layout of the record
+            --  for the overlay to shield ourselves from endianness issues.
 
-            BL : Length;
-            for BL'Address use BD.Len'Address;
-            pragma Import (Ada, BL);
+            type Bignum_Data_Header is record
+               Len : Length;
+               Neg : Boolean;
+            end record;
 
+            for Bignum_Data_Header use record
+               Len at 0 range 0 .. 23;
+               Neg at 3 range 0 .. 7;
+            end record;
+
+            BDH : Bignum_Data_Header;
+            for BDH'Address use BD'Address;
+            pragma Import (Ada, BDH);
+
+            pragma Assert (BDH.Len'Size = BD.Len'Size);
+
          begin
-            BL := Len;
+            BDH.Len := Len;
             return B;
          end;
       end if;