Skip to content
Snippets Groups Projects
Commit 2f0a62ff authored by Brian Carrier's avatar Brian Carrier
Browse files

Added comments and catch exception of vector can't be resized

parent a8364cdf
No related branches found
No related tags found
No related merge requests found
......@@ -36,10 +36,18 @@ namespace Rejistry {
_buffer.resize(capacity);
}
/**
* Makes a copy of the passed in buffer.
* @throws RegistryParseException if memory can't be allocated
*/
ByteBuffer::ByteBuffer(const uint8_t * buf, const uint32_t length) : Buffer(length) {
initializeBuffer(buf, length);
}
/**
* Makes a copy of the passed in buffer.
* @throws RegistryParseException if memory can't be allocated
*/
ByteBuffer::ByteBuffer(const ByteArray& buf, const uint32_t length) : Buffer(length) {
if (buf.size() > 0) {
initializeBuffer(&buf[0], length);
......@@ -47,7 +55,14 @@ namespace Rejistry {
}
void ByteBuffer::initializeBuffer(const uint8_t * buf, const uint32_t length) {
_buffer.resize(length);
try {
_buffer.resize(length);
}
catch (std::bad_alloc &e)
{
throw RegistryParseException("Cannot allocate memory for registry byte buffer.");
}
if (buf != NULL) {
memcpy(&_buffer[0], buf, length);
}
......
......@@ -39,7 +39,10 @@
namespace Rejistry {
std::wstring_convert<std::codecvt_utf16<wchar_t, 0x10ffff, std::little_endian>, wchar_t> conv;
/**
* Does NOT make a copy of the passed in buffer, but will free the memory when deleted
*/
RegistryByteBuffer::RegistryByteBuffer(ByteBuffer * buffer) {
if (buffer == NULL) {
throw std::invalid_argument("Buffer must not be null.");
......
......@@ -31,6 +31,10 @@
namespace Rejistry {
/**
* Makes a copy of the passed in buffer.
* @throws RegistryParseException if memory can't be allocated
*/
RegistryHiveBuffer::RegistryHiveBuffer(const uint8_t * buffer, const uint32_t size) {
_buffer = new RegistryByteBuffer(new ByteBuffer(buffer, size));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment