Skip to content

Commit bd1410d

Browse files
author
sprice
committed
Throw exceptions on save buffer failures.
1 parent c552e9b commit bd1410d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/cpp/flann/util/serialization.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,10 @@ class SaveArchive : public OutputArchive<SaveArchive>
391391

392392
// Construct the buffer
393393
char *compBuffer = (char *)malloc(LZ4_compressBound(offset_));
394+
if (compBuffer == NULL) {
395+
throw FLANNException("Error allocating compression buffer");
396+
}
397+
394398
size_t headSz = sizeof(IndexHeaderStruct);
395399
memcpy(compBuffer, buffer_, headSz);
396400

@@ -436,6 +440,9 @@ class SaveArchive : public OutputArchive<SaveArchive>
436440
void save(const T& val)
437441
{
438442
buffer_ = (char *)realloc(buffer_, offset_+sizeof(val));
443+
if (buffer_ == NULL) {
444+
throw FLANNException("Error reallocating compression buffer (save_binary())");
445+
}
439446
memcpy(buffer_+offset_, &val, sizeof(val));
440447
offset_ += sizeof(val);
441448
}
@@ -451,6 +458,9 @@ class SaveArchive : public OutputArchive<SaveArchive>
451458
void save_binary(T* ptr, size_t size)
452459
{
453460
buffer_ = (char *)realloc(buffer_, offset_+size);
461+
if (buffer_ == NULL) {
462+
throw FLANNException("Error reallocating compression buffer (save_binary())");
463+
}
454464
memcpy(buffer_+offset_, ptr, size);
455465
offset_ += size;
456466
}

0 commit comments

Comments
 (0)