From 7cb1c8b5868af097c238773db20ee7c42c81c321 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Fri, 4 Feb 2011 18:58:21 +0000 Subject: [PATCH] * improvement of r16001 so that allocations even closer to high(ptruint) also fail correctly rather than overflowing to 0 bytes (mantis #18690) git-svn-id: trunk@16877 - --- .gitattributes | 1 + rtl/inc/heap.inc | 3 ++- tests/webtbs/tw18690.pp | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/webtbs/tw18690.pp diff --git a/.gitattributes b/.gitattributes index b0453d3545..84dcaa4c76 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10968,6 +10968,7 @@ tests/webtbs/tw1862.pp svneol=native#text/plain tests/webtbs/tw18620.pp svneol=native#text/pascal tests/webtbs/tw1863.pp svneol=native#text/plain tests/webtbs/tw1867.pp svneol=native#text/plain +tests/webtbs/tw18690.pp svneol=native#text/plain tests/webtbs/tw1873.pp svneol=native#text/plain tests/webtbs/tw1883.pp svneol=native#text/plain tests/webtbs/tw1888.pp svneol=native#text/plain diff --git a/rtl/inc/heap.inc b/rtl/inc/heap.inc index 4e6b35d00f..386d021680 100644 --- a/rtl/inc/heap.inc +++ b/rtl/inc/heap.inc @@ -1045,7 +1045,8 @@ begin end else begin - size := (size+(sizeof(tmemchunk_var_hdr)+(blocksize-1))) and sizemask; + if size < high(ptruint)-((sizeof(tmemchunk_var_hdr)+(blocksize-1))) then + size := (size+(sizeof(tmemchunk_var_hdr)+(blocksize-1))) and sizemask; result := sysgetmem_var(size); end; diff --git a/tests/webtbs/tw18690.pp b/tests/webtbs/tw18690.pp new file mode 100644 index 0000000000..da3794aba7 --- /dev/null +++ b/tests/webtbs/tw18690.pp @@ -0,0 +1,17 @@ +Procedure AllocFreeGiB; + var + p: pointer; + RequestedSize: ptruint; + Begin + Writeln('-----------------------------'); + RequestedSize:=high(ptruint); // n GiB - 1 + Writeln('RequestedSize = ',RequestedSize,' bytes'); + getmem(p,RequestedSize); + if (p<>nil) then + halt(1); + End; + +Begin + ReturnNilIfGrowHeapFails:=true; + AllocFreeGiB; +End.