Explorar o código

Fix undefined behavior

Do not let the compiler optimize security check.
radl97 hai 1 ano
pai
achega
90849c02ce
Modificáronse 1 ficheiros con 2 adicións e 2 borrados
  1. 2 2
      squirrel/sqstate.cpp

+ 2 - 2
squirrel/sqstate.cpp

@@ -376,13 +376,13 @@ SQChar* SQSharedState::GetScratchPad(SQInteger size)
     SQInteger newsize;
     SQInteger newsize;
     if (size > 0) {
     if (size > 0) {
         if (_scratchpadsize < size) {
         if (_scratchpadsize < size) {
-            newsize = size + (size >> 1);
+            newsize = (SQInteger)((SQUnsignedInteger)size + (size >> 1));
             newsize = sq_max(newsize, size); //check for overflow
             newsize = sq_max(newsize, size); //check for overflow
             _scratchpad = (SQChar*)SQ_REALLOC(_scratchpad, _scratchpadsize, newsize);
             _scratchpad = (SQChar*)SQ_REALLOC(_scratchpad, _scratchpadsize, newsize);
             _scratchpadsize = newsize;
             _scratchpadsize = newsize;
 
 
         }
         }
-        else if (_scratchpadsize >= (size << 5)) {
+        else if ((_scratchpadsize >> 5) >= size) {
             newsize = _scratchpadsize >> 1;
             newsize = _scratchpadsize >> 1;
             newsize = sq_max(newsize, size); //check for overflow
             newsize = sq_max(newsize, size); //check for overflow
             _scratchpad = (SQChar*)SQ_REALLOC(_scratchpad, _scratchpadsize, newsize);
             _scratchpad = (SQChar*)SQ_REALLOC(_scratchpad, _scratchpadsize, newsize);