Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
4.8.5, 5.1.0
-
Windows 7 64-bit, OS X 10.8
Description
The code snippets are shown below.
QByteArray small; small.resize(1024); small.fill('s', 1024); QByteArray big; big.resize(1024*1024*1024); big.fill('b'); //The below lines will not work. big.append(small); //big += small; small.append(big); //small += big; //big.prepend(small);
A workaround for us is to validate the proper size if the one of the QByteArray already has a size more than half of INT_MAX value, as shown below.
const int HALF_INT_MAX = INT_MAX / 2; int combinedByteArraysSize = big.size() + small.size(); #if 1 if(combinedByteArraysSize > HALF_INT_MAX && combinedByteArraysSize < INT_MAX) { big.reserve(combinedByteArraysSize); big.append(small); //big += small; } #else //Below lines does not work on Windows system, but work on OS X system. if(combinedByteArraysSize > HALF_INT_MAX && combinedByteArraysSize < INT_MAX) { small.reserve(combinedByteArraysSize); small.append(big); //small += big; //big.prepend(small); } #endif
Please see bytearraytest_v1.zip for the full test program.