From 979b68a75bfb10d2df2167191df7e8e6dc692ba7 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Mon, 7 Oct 2002 12:51:25 +0000 Subject: [PATCH] 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 --- src/kits/support/DataIO.cpp | 24 ++++++++++++------------ src/kits/support/String.cpp | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/kits/support/DataIO.cpp b/src/kits/support/DataIO.cpp index 9066c7b038..f692f10a57 100644 --- a/src/kits/support/DataIO.cpp +++ b/src/kits/support/DataIO.cpp @@ -343,16 +343,13 @@ BMallocIO::WriteAt(off_t pos, const void *buffer, size_t size) size_t newSize = max(pos + size, static_cast(fLength)); status_t error = B_OK; - + if (newSize > fMallocSize) error = SetSize(newSize); - if (error == B_OK) { + if (error == B_OK) memcpy(fData + pos, buffer, size); - if (pos + size > fLength) - fLength = pos + size; - } - + return error != B_OK ? error : size; } @@ -395,23 +392,26 @@ BMallocIO::SetSize(off_t size) // size == 0, free the memory free(fData); fData = NULL; + fMallocSize = 0; } else { // size != 0, see, if necessary to resize - size = (size + fBlockSize - 1) / fBlockSize * fBlockSize; + size_t newSize = (size + fBlockSize - 1) / fBlockSize * fBlockSize; if (size != fMallocSize) { // we need to resize - if (char *newData = static_cast(realloc(fData, size))) { + if (char *newData = static_cast(realloc(fData, newSize))) { // set the new area to 0 - if (size > fMallocSize) - memset(newData + fMallocSize, 0, size - fMallocSize); + if (newSize > fMallocSize) + memset(newData + fMallocSize, 0, newSize - fMallocSize); fData = newData; - fMallocSize = size; + fMallocSize = newSize; } else // couldn't alloc the memory error = B_NO_MEMORY; } } + if (error == B_OK) - fLength = size; + fLength = size; + return error; } diff --git a/src/kits/support/String.cpp b/src/kits/support/String.cpp index 61c8a9d76d..7f85af0d90 100644 --- a/src/kits/support/String.cpp +++ b/src/kits/support/String.cpp @@ -1099,7 +1099,7 @@ BString::CharacterEscape(const char *original, const char *setOfCharsToEscape, c for(;;) { pos = strcspn(_privateData + offset, setOfCharsToEscape); offset += pos; - if (offset > Length()) + if (offset >= Length()) break; _OpenAtBy(offset, 1); memset(_privateData + offset, escapeWith, 1); @@ -1121,7 +1121,7 @@ BString::CharacterEscape(const char *setOfCharsToEscape, char escapeWith) for(;;) { pos = strcspn(_privateData + offset, setOfCharsToEscape); offset += pos; - if (offset > Length()) + if (offset >= Length()) break; _OpenAtBy(offset, 1); memset(_privateData + offset, escapeWith, 1);