From c4f5487ee9b60d2a1c0c3dbfedc8f9f377562bc6 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Sun, 22 May 2011 00:27:10 -0400 Subject: [PATCH] Fix handling of memopen size Signed-off-by: Mathieu Desnoyers --- formats/ctf/ctf.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index 41aa35d6..e84e19d8 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -489,6 +489,11 @@ int ctf_open_trace_metadata_stream_read(struct ctf_trace *td, FILE **fp, int ret; in = *fp; + /* + * Using strlen on *buf instead of size of open_memstream + * because its size includes garbage at the end (after final + * \0). This is the allocated size, not the actual string size. + */ out = open_memstream(buf, &size); if (out == NULL) return -errno; @@ -506,7 +511,7 @@ int ctf_open_trace_metadata_stream_read(struct ctf_trace *td, FILE **fp, fclose(out); /* flush the buffer */ fclose(in); /* open for reading */ - *fp = fmemopen(*buf, size, "rb"); + *fp = fmemopen(*buf, strlen(*buf), "rb"); return 0; } -- 2.34.1