]> gcc.gnu.org Git - gcc.git/commitdiff
[Ada] Zero-size slices
authorBob Duff <duff@adacore.com>
Fri, 26 Mar 2021 19:41:31 +0000 (15:41 -0400)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 21 Jun 2021 10:45:10 +0000 (06:45 -0400)
gcc/ada/

* libgnat/s-bituti.ads (Small_Size): Do not include 0 in this
type.
* libgnat/s-bituti.adb (Copy_Bitfield): Do nothing for 0-bit
bitfields.

gcc/ada/libgnat/s-bituti.adb
gcc/ada/libgnat/s-bituti.ads

index fbb53893f0f3b943769a535e2d74ac1ab9860a96..3e584e72bfe2db2dff39296a68feedbba25b37b4 100644 (file)
@@ -402,11 +402,22 @@ package body System.Bitfield_Utils is
          pragma Assert (Al_Src_Address mod Val'Alignment = 0);
          pragma Assert (Al_Dest_Address mod Val'Alignment = 0);
       begin
+         --  Optimized small case
+
          if Size in Small_Size then
             Copy_Small_Bitfield
               (Al_Src_Address, Al_Src_Offset,
                Al_Dest_Address, Al_Dest_Offset,
                Size);
+
+         --  Do nothing for zero size. This is necessary to avoid doing invalid
+         --  reads, which are detected by valgrind.
+
+         elsif Size = 0 then
+            null;
+
+         --  Large case
+
          else
             Copy_Large_Bitfield
               (Al_Src_Address, Al_Src_Offset,
index eb1662df7e98abfea1734a32ba807c13812c0168..c9c4b9184b9d6b89ea857d9d8cec074083544f1a 100644 (file)
@@ -98,9 +98,9 @@ package System.Bitfield_Utils is
       pragma Assert (Val_Array'Component_Size = Val'Size);
 
       subtype Bit_Size is Natural; -- Size in bits of a bit field
-      subtype Small_Size is Bit_Size range 0 .. Val'Size;
+      subtype Small_Size is Bit_Size range 1 .. Val'Size;
       --  Size of a small one
-      subtype Bit_Offset is Small_Size range 0 .. Val'Size - 1;
+      subtype Bit_Offset is Small_Size'Base range 0 .. Val'Size - 1;
       --  Starting offset
       subtype Bit_Offset_In_Byte is Bit_Offset range 0 .. Storage_Unit - 1;
 
This page took 0.065065 seconds and 5 git commands to generate.