X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/80e2389990082500d76eb566d4946be3e786c3ef..d8f41ccd20de16f8ebe2ccc84d47bf1cb2b26bbb:/libsecurity_filedb/lib/ReadWriteSection.cpp?ds=inline diff --git a/libsecurity_filedb/lib/ReadWriteSection.cpp b/libsecurity_filedb/lib/ReadWriteSection.cpp deleted file mode 100644 index de095ea9..00000000 --- a/libsecurity_filedb/lib/ReadWriteSection.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include "ReadWriteSection.h" - -uint32 WriteSection::put(uint32 inOffset, uint32 inValue) -{ - uint32 aLength = CheckUInt32Add(inOffset, sizeof(inValue)); - if (aLength > mCapacity) - grow(aLength); - - if (mAddress == NULL) - CssmError::throwMe(CSSMERR_DL_DATABASE_CORRUPT); - - *reinterpret_cast(mAddress + inOffset) = htonl(inValue); - return aLength; -} - - - -uint32 WriteSection::put(uint32 inOffset, uint32 inLength, const uint8 *inData) -{ - // if we are being asked to put 0 bytes, just return - if (inLength == 0 || inData == NULL) - { - return inOffset; - } - - uint32 aLength = CheckUInt32Add(inOffset, inLength); - - // Round up to nearest multiple of 4 bytes, to pad with zeros - uint32 aNewOffset = align(aLength); - if (aNewOffset > mCapacity) - grow(aNewOffset); - - if (mAddress == NULL) - CssmError::throwMe(CSSMERR_DL_DATABASE_CORRUPT); - - memcpy(mAddress + inOffset, inData, inLength); - - for (uint32 anOffset = aLength; anOffset < aNewOffset; anOffset++) - mAddress[anOffset] = 0; - - return aNewOffset; -} - - - -void WriteSection::grow(size_t inNewCapacity) -{ - size_t n = CheckUInt32Multiply((uint32)mCapacity, 2); - size_t aNewCapacity = max(n, inNewCapacity); - mAddress = reinterpret_cast(mAllocator.realloc(mAddress, aNewCapacity)); - memset(mAddress + mCapacity, 0, aNewCapacity - mCapacity); - mCapacity = aNewCapacity; -}