Skip to content

Commit 805fb76

Browse files
Paul KitchenPaul Kitchen
Paul Kitchen
authored and
Paul Kitchen
committed
Reserve extra byte in LoadDataFromFile() in case caller wants to append '\0'
1 parent 83ae900 commit 805fb76

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/ccutil/genericvector.h

+2
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ inline bool LoadDataFromFile(const char* filename, GenericVector<char>* data) {
375375
fseek(fp, 0, SEEK_SET);
376376
// Trying to open a directory on Linux sets size to LONG_MAX. Catch it here.
377377
if (size > 0 && size < LONG_MAX) {
378+
// reserve an extra byte in case caller wants to append a '\0' character
379+
data->reserve(size + 1);
378380
data->resize_no_init(size);
379381
result = static_cast<long>(fread(&(*data)[0], 1, size, fp)) == size;
380382
}

0 commit comments

Comments
 (0)