diff options
author | Bob Duff <duff@adacore.com> | 2020-04-10 18:23:15 -0400 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2020-06-17 04:14:11 -0400 |
commit | c602003b6a2552c01d77fd1fdd5f12848743075f (patch) | |
tree | 1e7cd76cceb0fb154536471344970a65f91fa59c /gcc/ada/libgnat/a-coinve.adb | |
parent | 4ea4df3af88f33686813b7db70fbe3e37b7dfecc (diff) | |
download | gcc-c602003b6a2552c01d77fd1fdd5f12848743075f.zip gcc-c602003b6a2552c01d77fd1fdd5f12848743075f.tar.gz gcc-c602003b6a2552c01d77fd1fdd5f12848743075f.tar.bz2 |
[Ada] Ada2020: AI12-0110 Tampering checks are performed first
2020-06-17 Bob Duff <duff@adacore.com>
gcc/ada/
* libgnat/a-cbdlli.adb, libgnat/a-cbhama.adb,
libgnat/a-cbhase.adb, libgnat/a-cbmutr.adb,
libgnat/a-cborma.adb, libgnat/a-cborse.adb,
libgnat/a-cdlili.adb, libgnat/a-chtgbk.adb,
libgnat/a-chtgke.adb, libgnat/a-cidlli.adb,
libgnat/a-cihama.adb, libgnat/a-cihase.adb,
libgnat/a-cimutr.adb, libgnat/a-ciorma.adb,
libgnat/a-ciorse.adb, libgnat/a-cobove.adb,
libgnat/a-cohama.adb, libgnat/a-cohase.adb,
libgnat/a-coinve.adb, libgnat/a-comutr.adb,
libgnat/a-convec.adb, libgnat/a-coorma.adb,
libgnat/a-coorse.adb, libgnat/a-crbtgk.adb,
libgnat/a-crbtgo.adb, libgnat/a-rbtgso.adb: Move tampering
checks earlier.
Diffstat (limited to 'gcc/ada/libgnat/a-coinve.adb')
-rw-r--r-- | gcc/ada/libgnat/a-coinve.adb | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/gcc/ada/libgnat/a-coinve.adb b/gcc/ada/libgnat/a-coinve.adb index 5ae3ffe..85c30fa 100644 --- a/gcc/ada/libgnat/a-coinve.adb +++ b/gcc/ada/libgnat/a-coinve.adb @@ -408,6 +408,14 @@ package body Ada.Containers.Indefinite_Vectors is J : Index_Type'Base; -- first index of items that slide down begin + -- The tampering bits exist to prevent an item from being deleted (or + -- otherwise harmfully manipulated) while it is being visited. Query, + -- Update, and Iterate increment the busy count on entry, and decrement + -- the count on exit. Delete checks the count to determine whether it is + -- being called while the associated callback procedure is executing. + + TC_Check (Container.TC); + -- Delete removes items from the vector, the number of which is the -- minimum of the specified Count and the items (if any) that exist from -- Index to Container.Last. There are no constraints on the specified @@ -460,14 +468,6 @@ package body Ada.Containers.Indefinite_Vectors is return; end if; - -- The tampering bits exist to prevent an item from being deleted (or - -- otherwise harmfully manipulated) while it is being visited. Query, - -- Update, and Iterate increment the busy count on entry, and decrement - -- the count on exit. Delete checks the count to determine whether it is - -- being called while the associated callback procedure is executing. - - TC_Check (Container.TC); - -- We first calculate what's available for deletion starting at -- Index. Here and elsewhere we use the wider of Index_Type'Base and -- Count_Type'Base as the type for intermediate values. (See function @@ -942,6 +942,8 @@ package body Ada.Containers.Indefinite_Vectors is I, J : Index_Type'Base; begin + TC_Check (Source.TC); + -- The semantics of Merge changed slightly per AI05-0021. It was -- originally the case that if Target and Source denoted the same -- container object, then the GNAT implementation of Merge did @@ -964,8 +966,6 @@ package body Ada.Containers.Indefinite_Vectors is return; end if; - TC_Check (Source.TC); - I := Target.Last; -- original value (before Set_Length) Target.Set_Length (Length (Target) + Length (Source)); @@ -1128,6 +1128,14 @@ package body Ada.Containers.Indefinite_Vectors is Dst : Elements_Access; -- new, expanded internal array begin + -- The tampering bits exist to prevent an item from being harmfully + -- manipulated while it is being visited. Query, Update, and Iterate + -- increment the busy count on entry, and decrement the count on + -- exit. Insert checks the count to determine whether it is being called + -- while the associated callback procedure is executing. + + TC_Check (Container.TC); + if Checks then -- As a precondition on the generic actual Index_Type, the base type -- must include Index_Type'Pred (Index_Type'First); this is the value @@ -1335,14 +1343,6 @@ package body Ada.Containers.Indefinite_Vectors is return; end if; - -- The tampering bits exist to prevent an item from being harmfully - -- manipulated while it is being visited. Query, Update, and Iterate - -- increment the busy count on entry, and decrement the count on - -- exit. Insert checks the count to determine whether it is being called - -- while the associated callback procedure is executing. - - TC_Check (Container.TC); - if New_Length <= Container.Elements.EA'Length then -- In this case, we're inserting elements into a vector that has @@ -1908,6 +1908,14 @@ package body Ada.Containers.Indefinite_Vectors is Dst : Elements_Access; -- new, expanded internal array begin + -- The tampering bits exist to prevent an item from being harmfully + -- manipulated while it is being visited. Query, Update, and Iterate + -- increment the busy count on entry, and decrement the count on exit. + -- Insert checks the count to determine whether it is being called while + -- the associated callback procedure is executing. + + TC_Check (Container.TC); + if Checks then -- As a precondition on the generic actual Index_Type, the base type -- must include Index_Type'Pred (Index_Type'First); this is the value @@ -2090,14 +2098,6 @@ package body Ada.Containers.Indefinite_Vectors is return; end if; - -- The tampering bits exist to prevent an item from being harmfully - -- manipulated while it is being visited. Query, Update, and Iterate - -- increment the busy count on entry, and decrement the count on exit. - -- Insert checks the count to determine whether it is being called while - -- the associated callback procedure is executing. - - TC_Check (Container.TC); - if New_Length <= Container.Elements.EA'Length then -- In this case, we are inserting elements into a vector that has @@ -2757,12 +2757,12 @@ package body Ada.Containers.Indefinite_Vectors is New_Item : Element_Type) is begin + TE_Check (Container.TC); + if Checks and then Index > Container.Last then raise Constraint_Error with "Index is out of range"; end if; - TE_Check (Container.TC); - declare X : Element_Access := Container.Elements.EA (Index); @@ -2784,6 +2784,8 @@ package body Ada.Containers.Indefinite_Vectors is New_Item : Element_Type) is begin + TE_Check (Container.TC); + if Checks then if Position.Container = null then raise Constraint_Error with "Position cursor has no element"; @@ -2798,8 +2800,6 @@ package body Ada.Containers.Indefinite_Vectors is end if; end if; - TE_Check (Container.TC); - declare X : Element_Access := Container.Elements.EA (Position.Index); @@ -3258,6 +3258,8 @@ package body Ada.Containers.Indefinite_Vectors is procedure Swap (Container : in out Vector; I, J : Index_Type) is begin + TE_Check (Container.TC); + if Checks then if I > Container.Last then raise Constraint_Error with "I index is out of range"; @@ -3272,8 +3274,6 @@ package body Ada.Containers.Indefinite_Vectors is return; end if; - TE_Check (Container.TC); - declare EI : Element_Access renames Container.Elements.EA (I); EJ : Element_Access renames Container.Elements.EA (J); |