Commit 1048a183 by Claire Dross Committed by Pierre-Marie de Rodat

[Ada] Memory corruption when using formal hashed sets or maps

Add a check to avoid causing a buffer overflow when the map is empty

2019-07-11  Claire Dross  <dross@adacore.com>

gcc/ada/

	* libgnat/a-cfhama.adb, libgnat/a-cfhase.adb (Free): Do not
	reset the Has_Element flag if no element is freed.

From-SVN: r273397
parent 9d80f439
2019-07-11 Claire Dross <dross@adacore.com>
* libgnat/a-cfhama.adb, libgnat/a-cfhase.adb (Free): Do not
reset the Has_Element flag if no element is freed.
2019-07-11 Arnaud Charlet <charlet@adacore.com>
* errno.c: Remove obsolete support for MaRTE OS.
......
......@@ -509,8 +509,11 @@ is
procedure Free (HT : in out Map; X : Count_Type) is
begin
HT.Nodes (X).Has_Element := False;
HT_Ops.Free (HT, X);
if X /= 0 then
pragma Assert (X <= HT.Capacity);
HT.Nodes (X).Has_Element := False;
HT_Ops.Free (HT, X);
end if;
end Free;
----------------------
......
......@@ -760,8 +760,11 @@ is
procedure Free (HT : in out Set; X : Count_Type) is
begin
HT.Nodes (X).Has_Element := False;
HT_Ops.Free (HT, X);
if X /= 0 then
pragma Assert (X <= HT.Capacity);
HT.Nodes (X).Has_Element := False;
HT_Ops.Free (HT, X);
end if;
end Free;
----------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment