]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Fix infinite loop that occurred in R_FrameData_Alloc if requesting > 256MB (which...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 27 Nov 2016 21:35:34 +0000 (21:35 +0000)
committerRudolf Polzer <divVerent@xonotic.org>
Tue, 29 Nov 2016 18:39:23 +0000 (19:39 +0100)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12295 d7cf8633-e32d-0410-b094-e92efae38249
::stable-branch::merge=b18cecd7b0c37e696571dcb3abb22a79ad03dae7

gl_rmain.c

index b0c146c0b07d3fd95ccf79c4561832029c1f351b..a97cfc034bcf0dcdfd52a511822181ddca5287d4 100644 (file)
@@ -4682,7 +4682,13 @@ void *R_FrameData_Alloc(size_t size)
        while (!r_framedata_mem || r_framedata_mem->current + size > r_framedata_mem->size)
        {
                // emergency - we ran out of space, allocate more memory
-               newvalue = bound(0.25f, r_framedatasize.value * 2.0f, 256.0f);
+               // note: this has no upper-bound, we'll fail to allocate memory eventually and just die
+               newvalue = r_framedatasize.value * 2.0f;
+               // upper bound based on architecture - if we try to allocate more than this we could overflow, better to loop until we error out on allocation failure
+               if (sizeof(size_t) >= 8)
+                       newvalue = bound(0.25f, newvalue, (float)(1ll << 42));
+               else
+                       newvalue = bound(0.25f, newvalue, (float)(1 << 10));
                // this might not be a growing it, but we'll allocate another buffer every time
                Cvar_SetValueQuick(&r_framedatasize, newvalue);
                R_FrameData_Resize(true);