Fix babeltrace-log get big line when the input file last line don't have enter
[babeltrace.git] / converter / babeltrace-log.c
index d3470774c589a22b143232b58add5df9f892c85b..f7eb5f768d39c88425f3bff276374f8ba47e9074 100644 (file)
@@ -20,6 +20,7 @@
  * Depends on glibc 2.10 for getline().
  */
 
+#define _GNU_SOURCE
 #include <config.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -229,6 +230,7 @@ void trace_text(FILE *input, int output)
        char *line = NULL, *nl;
        size_t linesize;
 
+       memset(&pos, 0, sizeof(pos));
        ctf_init_pos(&pos, output, O_RDWR);
 
        write_packet_header(&pos, s_uuid);
@@ -238,9 +240,12 @@ void trace_text(FILE *input, int output)
                if (len < 0)
                        break;
                nl = strrchr(line, '\n');
-               if (nl)
+               if (nl) {
                        *nl = '\0';
-               trace_string(line, &pos, nl - line + 1);
+                       trace_string(line, &pos, nl - line + 1);
+               } else {
+                       trace_string(line, &pos, strlen(line) + 1);
+               }
        }
        ctf_fini_pos(&pos);
 }
This page took 0.024574 seconds and 4 git commands to generate.