diff --git a/common/utils/itti_analyzer/libparser/array_type.c b/common/utils/itti_analyzer/libparser/array_type.c index 6379543f3db3123862560cc64d4936dafd3f36a3..87c9c2afd21181979aaef625731eab36a7c18303 100644 --- a/common/utils/itti_analyzer/libparser/array_type.c +++ b/common/utils/itti_analyzer/libparser/array_type.c @@ -51,13 +51,15 @@ int array_dissect_from_buffer( } /* Check if this is an array of 8 bits items and if at least the firsts ones are not null */ - if ((type_child->size == 8) && ((items - zero_counter) >= 2)) + if ((type_child->size == 8) && (zero_counter >= 1) && ((items - zero_counter) >= 2)) { + int end = items - zero_counter; + /* check if this is a printable string */ is_string = TRUE; - string = calloc(items + 1, 1); + string = malloc(end + 1); - for (i = 0; i < (items - zero_counter); i++) + for (i = 0; i < end; i++) { string[i] = fundamental_read_from_buffer(type_child, buffer, parent_offset, offset + i * type_child->size); if (isprint(string[i]) == 0) @@ -70,7 +72,8 @@ int array_dissect_from_buffer( if (is_string) { - INDENTED_STRING(cbuf, indent, length = sprintf(cbuf, "[%d .. %d] \"%s\"\n", 0, (items - zero_counter - 1), string)); + string[i] = '\0'; + INDENTED_STRING(cbuf, indent, length = sprintf(cbuf, "[0 .. %d] \"%s\"\n", end - 1, string)); ui_set_signal_text_cb(user_data, cbuf, length); } }