bitcoin/bitcoin — pull request #2705 by robbak (2013-05-29 02:22:28+00:00)
Title: Don't attempt to resize vector to negative size.

When my system crashes, the peers.dat file often ends up zero-sized. When this happens, vector vchData.resize(dataSize) is handed a negative dataSize. It takes it as an unsigned in and attempts to resize it to 18 hexillion bytes, crashing with a std::bad_alloc, which is presented as "bitcoin in Runaway exception"

This pull simply adds a 'if ( dataSize < 0 ) dataSize = 0;' check before running resize(). Another option would be to make the resize() call itself conditional on dataSize being positive.