1 #include "ReadWriteSection.h"
3 uint32
WriteSection::put(uint32 inOffset
, uint32 inValue
)
5 uint32 aLength
= CheckUInt32Add(inOffset
, sizeof(inValue
));
6 if (aLength
> mCapacity
)
10 CssmError::throwMe(CSSMERR_DL_DATABASE_CORRUPT
);
12 *reinterpret_cast<uint32
*>(mAddress
+ inOffset
) = htonl(inValue
);
18 uint32
WriteSection::put(uint32 inOffset
, uint32 inLength
, const uint8
*inData
)
20 // if we are being asked to put 0 bytes, just return
21 if (inLength
== 0 || inData
== NULL
)
26 uint32 aLength
= CheckUInt32Add(inOffset
, inLength
);
28 // Round up to nearest multiple of 4 bytes, to pad with zeros
29 uint32 aNewOffset
= align(aLength
);
30 if (aNewOffset
> mCapacity
)
34 CssmError::throwMe(CSSMERR_DL_DATABASE_CORRUPT
);
36 memcpy(mAddress
+ inOffset
, inData
, inLength
);
38 for (uint32 anOffset
= aLength
; anOffset
< aNewOffset
; anOffset
++)
39 mAddress
[anOffset
] = 0;
46 void WriteSection::grow(size_t inNewCapacity
)
48 size_t n
= CheckUInt32Multiply((uint32
)mCapacity
, 2);
49 size_t aNewCapacity
= max(n
, inNewCapacity
);
50 mAddress
= reinterpret_cast<uint8
*>(mAllocator
.realloc(mAddress
, aNewCapacity
));
53 CssmError::throwMe(CSSMERR_DL_DATABASE_CORRUPT
);
55 memset(mAddress
+ mCapacity
, 0, aNewCapacity
- mCapacity
);
56 mCapacity
= aNewCapacity
;