From f19d25dd8d3e521fab82195027cc08cd08cb80d8 Mon Sep 17 00:00:00 2001 From: George Hotz Date: Wed, 3 Jun 2020 14:22:45 -0700 Subject: [PATCH] calloc an extra byte in read_file --- selfdrive/common/util.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/selfdrive/common/util.c b/selfdrive/common/util.c index 9bdb23f99..1aed0eaae 100644 --- a/selfdrive/common/util.c +++ b/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);