]> 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)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 27 Nov 2016 21:35:34 +0000 (21:35 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12295 d7cf8633-e32d-0410-b094-e92efae38249

gl_rmain.c

index 349b78e58c41df61c960f293a3506414123f5f0c..8bf14a8afd42673e1fa13b42bc2deb6f3dcad96b 100644 (file)
@@ -4689,7 +4689,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);