]> git.sesse.net Git - stockfish/commit
Fix an hang on 32 bits while allocating big TT table
authorMarco Costalba <mcostalba@gmail.com>
Thu, 13 Jan 2011 18:25:42 +0000 (19:25 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Thu, 13 Jan 2011 21:03:18 +0000 (22:03 +0100)
commit6442981cb649d2008275f12564aeeb69e73f41f5
treef6155c7a6b69a9de0eb0db5cfa80aea4a29019a1
parentd4b92ae9a094e1b388e3d70789a0db9a9c69cbdf
Fix an hang on 32 bits while allocating big TT table

If size_t is defined as a 32 bit quanitity then we have an
overflow in the left term of the while condition if mbSize
is bigger then 2048.

For instance if mbSize is 2049 then when newSize will reach
0x80000000 (2048MB) comparison is still true, 'while' loops
again and we have an overflow in the expression (2*newSize)
so that result is 0 and at that point 'while' keeps looping
forever hanging the application.

This patch fixes the bug and also makes operator new do not
throw an exception upon failure but return a NULL pointer
instead.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/tt.cpp
src/tt.h