From abc40d240660a2f727092bc7fcd727f6d5c82c16 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Thu, 14 Feb 2013 17:25:21 -0500 Subject: [PATCH] Cleanup error messages Ensure we print a more meaningful error message when empty metadata string is encountered. Signed-off-by: Mathieu Desnoyers --- formats/ctf/ctf.c | 14 +++++++++++--- lib/context.c | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index deb9a66d..552133c3 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -961,7 +961,7 @@ int ctf_open_trace_metadata_stream_read(struct ctf_trace *td, FILE **fp, char **buf) { FILE *in, *out; - size_t size; + size_t size, buflen; int ret; in = *fp; @@ -1003,7 +1003,12 @@ int ctf_open_trace_metadata_stream_read(struct ctf_trace *td, FILE **fp, perror("Error in fclose"); } /* open for reading */ - *fp = babeltrace_fmemopen(*buf, strlen(*buf), "rb"); + buflen = strlen(*buf); + if (!buflen) { + *fp = NULL; + return -ENODATA; + } + *fp = babeltrace_fmemopen(*buf, buflen, "rb"); if (!*fp) { perror("Metadata fmemopen"); return -errno; @@ -1060,8 +1065,11 @@ int ctf_open_trace_metadata_read(struct ctf_trace *td, if (packet_metadata(td, fp)) { ret = ctf_open_trace_metadata_stream_read(td, &fp, &buf); - if (ret) + if (ret) { + /* Warn about empty metadata */ + fprintf(stderr, "[warning] Empty metadata.\n"); goto end_packet_read; + } } else { unsigned int major, minor; ssize_t nr_items; diff --git a/lib/context.c b/lib/context.c index d0674223..b728298c 100644 --- a/lib/context.c +++ b/lib/context.c @@ -90,7 +90,7 @@ int bt_context_add_trace(struct bt_context *ctx, const char *path, if (path) { td = fmt->open_trace(path, O_RDONLY, packet_seek, NULL); if (!td) { - fprintf(stderr, "[warning] [Context] Cannot open_trace of format %s at path %s.\n\n", + fprintf(stderr, "[warning] [Context] Cannot open_trace of format %s at path %s.\n", format_name, path); ret = -1; goto end; -- 2.34.1