diff options
author | Steven Rostedt <srostedt@redhat.com> | 2011-03-18 08:46:01 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2011-03-18 08:46:01 -0400 |
commit | 4d431008a2cb5d24f9ed8802e28b04300eea34d6 (patch) | |
tree | 1f69faeb34658b3dba4bfbdf88020ea823f793ba | |
parent | a2e45373cdb660ef77cfb71f7b11b9323f108d8a (diff) |
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 <rostedt@goodmis.org>
-rw-r--r-- | trace-record.c | 5 |
1 files 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) | |||
1697 | if (r <= 0) | 1697 | if (r <= 0) |
1698 | continue; | 1698 | continue; |
1699 | if (size) { | 1699 | if (size) { |
1700 | buf = realloc(buf, size+r); | 1700 | buf = realloc(buf, size+r+1); |
1701 | if (!buf) | 1701 | if (!buf) |
1702 | die("malloc"); | 1702 | die("malloc"); |
1703 | } else | 1703 | } else |
1704 | buf = malloc_or_die(r); | 1704 | buf = malloc_or_die(r+1); |
1705 | memcpy(buf+size, buffer, r); | 1705 | memcpy(buf+size, buffer, r); |
1706 | size += r; | 1706 | size += r; |
1707 | } while (r); | 1707 | } while (r); |
1708 | 1708 | ||
1709 | buf[size] = '\0'; | ||
1709 | *psize = size; | 1710 | *psize = size; |
1710 | return buf; | 1711 | return buf; |
1711 | } | 1712 | } |