diff --git a/src/cobhan_buffer.h b/src/cobhan_buffer.h index 802656b..6348a8f 100644 --- a/src/cobhan_buffer.h +++ b/src/cobhan_buffer.h @@ -23,7 +23,7 @@ class CobhanBuffer { explicit CobhanBuffer(size_t data_len_bytes) { if (data_len_bytes > max_int32_size) { throw std::invalid_argument( - "Requested data length exceeds maximum allowable size"); + "CobhanBuffer(size_t): Requested data length exceeds maximum allowable size (2GB limit)"); } allocation_size = DataSizeToAllocationSize(data_len_bytes); cbuffer = new char[allocation_size]; @@ -37,7 +37,7 @@ class CobhanBuffer { : cbuffer(cbuffer), allocation_size(allocation_size), ownership(false) { if (allocation_size > max_int32_size) { throw std::invalid_argument( - "Allocation size exceeds maximum allowable size"); + "CobhanBuffer(char*, size_t): Allocation size exceeds maximum allowable size (2GB limit)"); } initialize(); } @@ -114,7 +114,7 @@ class CobhanBuffer { + safety_padding_bytes; // Add safety padding if configured if (allocation > max_int32_size) { throw std::invalid_argument( - "Calculated allocation size exceeds maximum allowable size"); + "CobhanBuffer::DataSizeToAllocationSize: Calculated allocation size exceeds maximum allowable size (2GB limit)"); } return allocation; } @@ -130,7 +130,7 @@ class CobhanBuffer { canary_size_bytes - safety_padding_bytes; if (data_len_bytes > max_int32_size) { throw std::invalid_argument( - "Calculated data size exceeds maximum allowable size"); + "CobhanBuffer::AllocationSizeToMaxDataSize: Calculated data size exceeds maximum allowable size (2GB limit)"); } return data_len_bytes; } @@ -171,11 +171,11 @@ class CobhanBuffer { void set_data_len_bytes(size_t data_len_bytes) { if (data_len_bytes > max_int32_size) { throw std::invalid_argument( - "Requested data length exceeds maximum allowable size"); + "CobhanBuffer::set_data_len_bytes: Requested data length exceeds maximum allowable size (2GB limit)"); } if (data_len_bytes > max_data_size) { throw std::invalid_argument( - "Requested data length exceeds allocation size"); + "CobhanBuffer::set_data_len_bytes: Requested data length exceeds buffer maximum data size"); } *data_len_ptr = static_cast(data_len_bytes); } @@ -204,7 +204,7 @@ class CobhanBuffer { } if (data_len_bytes > max_int32_size) { - throw std::invalid_argument("Data length exceeds maximum allowable size"); + throw std::invalid_argument("CobhanBuffer::initialize: Data length exceeds maximum allowable size (2GB limit)"); } // Write Cobhan header values @@ -249,7 +249,7 @@ class CobhanBuffer { allocation_size = other.allocation_size; if (allocation_size > max_int32_size) { throw std::invalid_argument( - "Allocation size exceeds maximum allowable size"); + "CobhanBuffer::moveFrom: Allocation size exceeds maximum allowable size (2GB limit)"); } cbuffer = new char[allocation_size]; diff --git a/src/cobhan_buffer_napi.h b/src/cobhan_buffer_napi.h index bf3e379..79461dc 100644 --- a/src/cobhan_buffer_napi.h +++ b/src/cobhan_buffer_napi.h @@ -103,9 +103,8 @@ class CobhanBufferNapi : public CobhanBuffer { env, get_data_ptr(), get_data_len_bytes(), &napiStr); if (status != napi_ok) { - napi_throw_error(env, nullptr, - "Failed to create Napi::String from CobhanBuffer"); - return {}; + NapiUtils::ThrowException(env, + "CobhanBufferNapi::ToString: Failed to create Napi::String from CobhanBuffer"); } return {env, napiStr};