From: Jérémie Galarneau Date: Mon, 24 Jul 2017 21:26:57 +0000 (-0400) Subject: Fix: Dereference null return value X-Git-Tag: v2.0.0-pre4~190 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=d1f0e0e31377de33b95baf5070ac95ea0cb88bba Fix: Dereference null return value Found by Coverity: 3. returned_null: bt_ctf_field_string_get_value returns null (checked 10 out of 12 times). CID 1376192 (#1 of 1): Dereference null return value (NULL_RETURNS) 4. dereference: Dereferencing a pointer that might be null bt_ctf_field_string_get_value(field) when calling print_escape_string. Signed-off-by: Jérémie Galarneau --- diff --git a/plugins/text/pretty/print.c b/plugins/text/pretty/print.c index 7cf9434d..97e9bf11 100644 --- a/plugins/text/pretty/print.c +++ b/plugins/text/pretty/print.c @@ -1317,14 +1317,23 @@ enum bt_component_status print_field(struct pretty_component *pretty, case CTF_TYPE_ENUM: return print_enum(pretty, field); case CTF_TYPE_STRING: + { + const char *str; + + str = bt_ctf_field_string_get_value(field); + if (!str) { + return BT_COMPONENT_STATUS_ERROR; + } + if (pretty->use_colors) { g_string_append(pretty->string, COLOR_STRING_VALUE); } - print_escape_string(pretty, bt_ctf_field_string_get_value(field)); + print_escape_string(pretty, str); if (pretty->use_colors) { g_string_append(pretty->string, COLOR_RST); } return BT_COMPONENT_STATUS_OK; + } case CTF_TYPE_STRUCT: return print_struct(pretty, field, print_names, filter_fields, filter_array_len);