Fix handling of memopen size
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 22 May 2011 04:27:10 +0000 (00:27 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 22 May 2011 04:27:10 +0000 (00:27 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/ctf.c

index 41aa35d60fd6a67e23b128a60a258ed03215bab2..e84e19d870e0d5bd1531e8cdb9266effa2d6806b 100644 (file)
@@ -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;
 }
 
This page took 0.02452 seconds and 4 git commands to generate.