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:
Stefano Ceccherini
2002-10-07 12:51:25 +00:00
parent fde69fce63
commit 979b68a75b
2 changed files with 14 additions and 14 deletions
+12 -12
View File
@@ -343,16 +343,13 @@ BMallocIO::WriteAt(off_t pos, const void *buffer, size_t size)
size_t newSize = max(pos + size, static_cast<off_t>(fLength)); size_t newSize = max(pos + size, static_cast<off_t>(fLength));
status_t error = B_OK; status_t error = B_OK;
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;
} }
+2 -2
View File
@@ -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);