Fixed a stupid bug in BString::CharacterEscape() and committed the correct version of DataIO.cpp (the former was an incorrect version)
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1429 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -347,11 +347,8 @@ BMallocIO::WriteAt(off_t pos, const void *buffer, size_t size)
|
|||||||
if (newSize > fMallocSize)
|
if (newSize > fMallocSize)
|
||||||
error = SetSize(newSize);
|
error = SetSize(newSize);
|
||||||
|
|
||||||
if (error == B_OK) {
|
if (error == B_OK)
|
||||||
memcpy(fData + pos, buffer, size);
|
memcpy(fData + pos, buffer, size);
|
||||||
if (pos + size > fLength)
|
|
||||||
fLength = pos + size;
|
|
||||||
}
|
|
||||||
|
|
||||||
return error != B_OK ? error : size;
|
return error != B_OK ? error : size;
|
||||||
}
|
}
|
||||||
@@ -395,23 +392,26 @@ BMallocIO::SetSize(off_t size)
|
|||||||
// size == 0, free the memory
|
// size == 0, free the memory
|
||||||
free(fData);
|
free(fData);
|
||||||
fData = NULL;
|
fData = NULL;
|
||||||
|
fMallocSize = 0;
|
||||||
} else {
|
} else {
|
||||||
// size != 0, see, if necessary to resize
|
// size != 0, see, if necessary to resize
|
||||||
size = (size + fBlockSize - 1) / fBlockSize * fBlockSize;
|
size_t newSize = (size + fBlockSize - 1) / fBlockSize * fBlockSize;
|
||||||
if (size != fMallocSize) {
|
if (size != fMallocSize) {
|
||||||
// we need to resize
|
// we need to resize
|
||||||
if (char *newData = static_cast<char*>(realloc(fData, size))) {
|
if (char *newData = static_cast<char*>(realloc(fData, newSize))) {
|
||||||
// set the new area to 0
|
// set the new area to 0
|
||||||
if (size > fMallocSize)
|
if (newSize > fMallocSize)
|
||||||
memset(newData + fMallocSize, 0, size - fMallocSize);
|
memset(newData + fMallocSize, 0, newSize - fMallocSize);
|
||||||
fData = newData;
|
fData = newData;
|
||||||
fMallocSize = size;
|
fMallocSize = newSize;
|
||||||
} else // couldn't alloc the memory
|
} else // couldn't alloc the memory
|
||||||
error = B_NO_MEMORY;
|
error = B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error == B_OK)
|
if (error == B_OK)
|
||||||
fLength = size;
|
fLength = size;
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1099,7 +1099,7 @@ BString::CharacterEscape(const char *original, const char *setOfCharsToEscape, c
|
|||||||
for(;;) {
|
for(;;) {
|
||||||
pos = strcspn(_privateData + offset, setOfCharsToEscape);
|
pos = strcspn(_privateData + offset, setOfCharsToEscape);
|
||||||
offset += pos;
|
offset += pos;
|
||||||
if (offset > Length())
|
if (offset >= Length())
|
||||||
break;
|
break;
|
||||||
_OpenAtBy(offset, 1);
|
_OpenAtBy(offset, 1);
|
||||||
memset(_privateData + offset, escapeWith, 1);
|
memset(_privateData + offset, escapeWith, 1);
|
||||||
@@ -1121,7 +1121,7 @@ BString::CharacterEscape(const char *setOfCharsToEscape, char escapeWith)
|
|||||||
for(;;) {
|
for(;;) {
|
||||||
pos = strcspn(_privateData + offset, setOfCharsToEscape);
|
pos = strcspn(_privateData + offset, setOfCharsToEscape);
|
||||||
offset += pos;
|
offset += pos;
|
||||||
if (offset > Length())
|
if (offset >= Length())
|
||||||
break;
|
break;
|
||||||
_OpenAtBy(offset, 1);
|
_OpenAtBy(offset, 1);
|
||||||
memset(_privateData + offset, escapeWith, 1);
|
memset(_privateData + offset, escapeWith, 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user