calloc an extra byte in read_file

pull/49/head
George Hotz 5 years ago
parent 4e7fe3a9ec
commit f19d25dd8d
  1. 4
      selfdrive/common/util.c

@ -19,7 +19,9 @@ void* read_file(const char* path, size_t* out_len) {
long f_len = ftell(f);
rewind(f);
char* buf = (char*)calloc(f_len, 1);
// calloc one extra byte so the file will always be NULL terminated
// cl_cached_program_from_file relies on this
char* buf = (char*)calloc(f_len+1, 1);
assert(buf);
size_t num_read = fread(buf, f_len, 1, f);

Loading…
Cancel
Save