Quellcode durchsuchen

* 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 -

Jonas Maebe vor 14 Jahren
Ursprung
Commit
7cb1c8b586
3 geänderte Dateien mit 20 neuen und 1 gelöschten Zeilen
  1. 1 0
      .gitattributes
  2. 2 1
      rtl/inc/heap.inc
  3. 17 0
      tests/webtbs/tw18690.pp

+ 1 - 0
.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

+ 2 - 1
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;
 

+ 17 - 0
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.