diff options
-rw-r--r-- | host/lib/include/host_misc.h | 1 | ||||
-rw-r--r-- | host/lib21/host_misc.c | 3 |
2 files changed, 3 insertions, 1 deletions
diff --git a/host/lib/include/host_misc.h b/host/lib/include/host_misc.h index 9759d44d..0249420b 100644 --- a/host/lib/include/host_misc.h +++ b/host/lib/include/host_misc.h @@ -44,6 +44,7 @@ vb2_error_t WriteFile(const char* filename, const void *data, uint64_t size); /** * Read data from a file into a newly allocated buffer. + * The buffer will end with an extra null byte ('\0', not counted in size). * * @param filename Name of file to read from * @param data_ptr On exit, pointer to newly allocated buffer with data diff --git a/host/lib21/host_misc.c b/host/lib21/host_misc.c index ebc4eac5..6c0e0ef3 100644 --- a/host/lib21/host_misc.c +++ b/host/lib21/host_misc.c @@ -42,11 +42,12 @@ vb2_error_t vb2_read_file(const char *filename, uint8_t **data_ptr, return VB2_ERROR_READ_FILE_SIZE; } - buf = malloc(size); + buf = malloc(size + 1); if (!buf) { fclose(f); return VB2_ERROR_READ_FILE_ALLOC; } + buf[size] = '\0'; if(1 != fread(buf, size, 1, f)) { VB2_DEBUG("Unable to read file %s\n", filename); |