adding unit tests and fixing same overflow issue in hpp files

This commit is contained in:
jwang
2018-08-29 16:02:14 -07:00
committed by tbeu
parent b3dfe28be4
commit 60930f4b12
3 changed files with 37 additions and 1 deletions

View File

@@ -71,6 +71,12 @@ public:
m_end = array + nfirst;
m_array = array;
if((sizeof(chunk) + chunk_size) < chunk_size){
throw std::bad_alloc();
}
chunk* c = static_cast<chunk*>(::malloc(sizeof(chunk) + chunk_size));
if(!c) {
::free(array);
@@ -141,7 +147,11 @@ public:
if(sz < len) {
sz = len;
}
if(sizeof(chunk) + sz < sz){
throw std::bad_alloc();
}
chunk* c = static_cast<chunk*>(::malloc(sizeof(chunk) + sz));
if(!c) {
throw std::bad_alloc();
@@ -183,6 +193,10 @@ public:
{
size_t sz = m_chunk_size;
if((sizeof(chunk) + sz) < sz){
throw std::bad_alloc();
}
chunk* empty = static_cast<chunk*>(::malloc(sizeof(chunk) + sz));
if(!empty) {
throw std::bad_alloc();