Details
-
Bug
-
Resolution: Invalid
-
P1: Critical
-
4.6.1
-
None
-
Ubuntu Linux 8.0
-
d3f6e14066219a957f48d24e9f39d3d0c5a61f53
Description
QByteArray::replace() invoked on a raw char array break the array size to the first \0 encountered.
That is not the expected behaviour than copying each char of the whole array.
Being an array, not just a string, I expected the \0 doesn't break the QbyteArray size except for those string-like methods.
I suggest to treat size() and length() method differently: size means the actual allocated space, length is for string-like evaluation.
To reproduce the error, run the code below:
void printArray(QByteArray& ba)
{
qDebug("\n");
for (int i = 0 ; i < ba.size(); i++)
qDebug("%x", (unsigned char)ba.at);
}
void main()
{
QByteArray qba;
char testReplace[] = "abcde\0fghijk";
qba.resize(sizeof(testReplace));
qba.replace(0, 13, testReplace);
printArray(qba);
qba.resize(sizeof(testReplace));
for(int i = 0; i < sizeof(testReplace); i++)
qba[i] = testReplace[i];
printArray(qba);
}