From 4d431008a2cb5d24f9ed8802e28b04300eea34d6 Mon Sep 17 00:00:00 2001 From: Steven Rostedt Date: Fri, 18 Mar 2011 08:46:01 -0400 Subject: trace-cmd-record: Have read_file() NULL terminate the buffer Add the '\0' string terminator to the buffer that read the file to make it easier for users of read_file() to treat the read file as a string and not worry about the size. Signed-off-by: Steven Rostedt --- trace-record.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/trace-record.c b/trace-record.c index c029257..e10e4d3 100644 --- a/trace-record.c +++ b/trace-record.c @@ -1697,15 +1697,16 @@ static char *read_file(char *file, int *psize) if (r <= 0) continue; if (size) { - buf = realloc(buf, size+r); + buf = realloc(buf, size+r+1); if (!buf) die("malloc"); } else - buf = malloc_or_die(r); + buf = malloc_or_die(r+1); memcpy(buf+size, buffer, r); size += r; } while (r); + buf[size] = '\0'; *psize = size; return buf; } -- cgit v1.2.2