Move overflow check up

This commit is contained in:
tbeu
2018-09-06 15:09:52 +02:00
parent 349c133171
commit d72765870a
2 changed files with 8 additions and 10 deletions

View File

@@ -58,6 +58,10 @@ public:
:m_ref_size(std::max(ref_size, detail::packer_max_buffer_size + 1)),
m_chunk_size(chunk_size)
{
if((sizeof(chunk) + chunk_size) < chunk_size) {
throw std::bad_alloc();
}
size_t nfirst = (sizeof(iovec) < 72/2) ?
72 / sizeof(iovec) : 8;
@@ -71,11 +75,6 @@ public:
m_end = array + nfirst;
m_array = array;
if((sizeof(chunk) + chunk_size) < chunk_size){
::free(array);
throw std::bad_alloc();
}
chunk* c = static_cast<chunk*>(::malloc(sizeof(chunk) + chunk_size));
if(!c) {
::free(array);