Przeglądaj źródła

* immediately fail when trying to allocate a memory block whose size falls
in the range high(ptruint)-$fffe .. high(ptruint), because all large
allocations are rounded up to the next multiple of 64kb, which is 0 in
that case (mantis #17430)

git-svn-id: trunk@16001 -

Jonas Maebe 15 lat temu
rodzic
commit
242016312f
3 zmienionych plików z 20 dodań i 0 usunięć
  1. 1 0
      .gitattributes
  2. 7 0
      rtl/inc/heap.inc
  3. 12 0
      tests/webtbs/tw17430.pp

+ 1 - 0
.gitattributes

@@ -10659,6 +10659,7 @@ tests/webtbs/tw17379a.pp svneol=native#text/plain
 tests/webtbs/tw17402.pp svneol=native#text/pascal
 tests/webtbs/tw17402a.pp svneol=native#text/pascal
 tests/webtbs/tw17413.pp svneol=native#text/plain
+tests/webtbs/tw17430.pp svneol=native#text/plain
 tests/webtbs/tw1744.pp svneol=native#text/plain
 tests/webtbs/tw1754c.pp svneol=native#text/plain
 tests/webtbs/tw1755.pp svneol=native#text/plain

+ 7 - 0
rtl/inc/heap.inc

@@ -970,6 +970,13 @@ var
   iter : cardinal;
 begin
   result:=nil;
+  { check for maximum possible allocation (everything is rounded up to the
+    next multiple of 64k) }
+  if (size>high(ptruint)-$ffff) then
+    if ReturnNilIfGrowHeapFails then
+      exit
+    else
+      HandleError(204);
   { free pending items }
   loc_freelists := @freelists;
   try_finish_waitvarlist(loc_freelists);

+ 12 - 0
tests/webtbs/tw17430.pp

@@ -0,0 +1,12 @@
+program Project1;
+
+{$mode delphi}{$H+}
+
+var
+  p:pointer;
+begin
+  returnnilifgrowheapfails:=true;
+  GetMem(p,ptruint(-128));
+  if assigned(p) then
+    halt(1);
+end.