From 08c82b90d94a6dfee1f3da4ec06864c6045c07f7 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 22 Oct 2012 18:31:11 -0400 Subject: [PATCH] Cleanup: fix cppcheck warnings Signed-off-by: Mathieu Desnoyers --- converter/babeltrace-log.c | 35 +++++++++++-------- converter/babeltrace.c | 3 +- formats/ctf-text/types/enum.c | 4 ++- formats/ctf/ctf.c | 8 +++-- .../metadata/ctf-visitor-generate-io-struct.c | 14 ++++++-- formats/ctf/types/float.c | 2 +- types/float.c | 3 +- types/types.c | 7 ++-- 8 files changed, 48 insertions(+), 28 deletions(-) diff --git a/converter/babeltrace-log.c b/converter/babeltrace-log.c index 9d87776a..8d425be6 100644 --- a/converter/babeltrace-log.c +++ b/converter/babeltrace-log.c @@ -164,13 +164,14 @@ void write_event_header(struct ctf_stream_pos *pos, char *line, uint64_t *ts) { unsigned long sec, usec; - int ret; if (!s_timestamp) return; /* Only need to be executed on first pass (dummy) */ if (pos->dummy) { + int ret; + /* Extract time from input line */ ret = sscanf(line, "[%lu.%lu] ", &sec, &usec); if (ret == 2) { @@ -201,21 +202,25 @@ void trace_string(char *line, struct ctf_stream_pos *pos, size_t len) uint64_t ts = 0; printf_debug("read: %s\n", line); -retry: - ctf_dummy_pos(pos, &dummy); - write_event_header(&dummy, line, &tline, len, &tlen, &ts); - ctf_align_pos(&dummy, sizeof(uint8_t) * CHAR_BIT); - ctf_move_pos(&dummy, tlen * CHAR_BIT); - if (ctf_pos_packet(&dummy)) { - ctf_pos_pad_packet(pos); - write_packet_header(pos, s_uuid); - write_packet_context(pos); - if (attempt++ == 1) { - fprintf(stderr, "[Error] Line too large for packet size (%" PRIu64 "kB) (discarded)\n", - pos->packet_size / CHAR_BIT / 1024); - return; + + for (;;) { + ctf_dummy_pos(pos, &dummy); + write_event_header(&dummy, line, &tline, len, &tlen, &ts); + ctf_align_pos(&dummy, sizeof(uint8_t) * CHAR_BIT); + ctf_move_pos(&dummy, tlen * CHAR_BIT); + if (ctf_pos_packet(&dummy)) { + ctf_pos_pad_packet(pos); + write_packet_header(pos, s_uuid); + write_packet_context(pos); + if (attempt++ == 1) { + fprintf(stderr, "[Error] Line too large for packet size (%" PRIu64 "kB) (discarded)\n", + pos->packet_size / CHAR_BIT / 1024); + return; + } + continue; + } else { + break; } - goto retry; } write_event_header(pos, line, &tline, len, &tlen, &ts); diff --git a/converter/babeltrace.c b/converter/babeltrace.c index b24d0102..d3fa02ac 100644 --- a/converter/babeltrace.c +++ b/converter/babeltrace.c @@ -459,7 +459,6 @@ int bt_context_add_traces_recursive(struct bt_context *ctx, const char *path, GArray *trace_ids; int ret = 0; - int i; /* Should lock traversed_paths mutex here if used in multithread */ @@ -470,6 +469,8 @@ int bt_context_add_traces_recursive(struct bt_context *ctx, const char *path, /* Process the array if ntfw did not return a fatal error */ if (ret >= 0) { + int i; + for (i = 0; i < traversed_paths->len; i++) { GString *trace_path = g_ptr_array_index(traversed_paths, i); diff --git a/formats/ctf-text/types/enum.c b/formats/ctf-text/types/enum.c index b973d494..11529dd9 100644 --- a/formats/ctf-text/types/enum.c +++ b/formats/ctf-text/types/enum.c @@ -30,7 +30,7 @@ int ctf_text_enum_write(struct stream_pos *ppos, struct definition *definition) enum_definition->integer; struct ctf_text_stream_pos *pos = ctf_text_pos(ppos); GArray *qs; - int i, ret; + int ret; int field_nr_saved; if (!print_field(definition)) @@ -53,6 +53,8 @@ int ctf_text_enum_write(struct stream_pos *ppos, struct definition *definition) qs = enum_definition->value; if (qs) { + int i; + for (i = 0; i < qs->len; i++) { GQuark q = g_array_index(qs, GQuark, i); const char *str = g_quark_to_string(q); diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index 37e31484..8029512a 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -583,11 +583,11 @@ int ctf_init_pos(struct ctf_stream_pos *pos, int fd, int open_flags) int ctf_fini_pos(struct ctf_stream_pos *pos) { - int ret; - if (pos->prot == PROT_WRITE && pos->content_size_loc) *pos->content_size_loc = pos->offset; if (pos->base_mma) { + int ret; + /* unmap old base */ ret = munmap_align(pos->base_mma); if (ret) { @@ -1940,9 +1940,11 @@ static int ctf_close_trace(struct trace_descriptor *tdp) { struct ctf_trace *td = container_of(tdp, struct ctf_trace, parent); - int i, ret; + int ret; if (td->streams) { + int i; + for (i = 0; i < td->streams->len; i++) { struct ctf_stream_declaration *stream; int j; diff --git a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c index 64c19677..7cc84953 100644 --- a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c +++ b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c @@ -890,7 +890,6 @@ struct declaration *ctf_declaration_variant_visit(FILE *fd, struct declaration_untagged_variant *untagged_variant_declaration; struct declaration_variant *variant_declaration; struct ctf_node *iter; - int ret; /* * For named variant (without body), lookup in @@ -916,12 +915,16 @@ struct declaration *ctf_declaration_variant_visit(FILE *fd, } untagged_variant_declaration = untagged_variant_declaration_new(declaration_scope); bt_list_for_each_entry(iter, declaration_list, siblings) { + int ret; + ret = ctf_variant_declaration_list_visit(fd, depth + 1, iter, untagged_variant_declaration, trace); if (ret) goto error; } if (name) { + int ret; + ret = register_variant_declaration(g_quark_from_string(name), untagged_variant_declaration, declaration_scope); @@ -1051,7 +1054,6 @@ struct declaration *ctf_declaration_enum_visit(FILE *fd, int depth, struct last_enum_value last_value; struct ctf_node *iter; GQuark dummy_id; - int ret; /* * For named enum (without body), lookup in @@ -1107,12 +1109,16 @@ struct declaration *ctf_declaration_enum_visit(FILE *fd, int depth, last_value.u.u = 0; } bt_list_for_each_entry(iter, enumerator_list, siblings) { + int ret; + ret = ctf_enumerator_list_visit(fd, depth + 1, iter, enum_declaration, &last_value); if (ret) goto error; } if (name) { + int ret; + ret = register_enum_declaration(g_quark_from_string(name), enum_declaration, declaration_scope); @@ -2960,18 +2966,20 @@ error: int ctf_destroy_metadata(struct ctf_trace *trace) { - int i, j, k; + int i; struct ctf_file_stream *metadata_stream; if (trace->streams) { for (i = 0; i < trace->streams->len; i++) { struct ctf_stream_declaration *stream; + int j; stream = g_ptr_array_index(trace->streams, i); if (!stream) continue; for (j = 0; j < stream->streams->len; j++) { struct ctf_stream_definition *stream_def; + int k; stream_def = g_ptr_array_index(stream->streams, j); if (!stream_def) diff --git a/formats/ctf/types/float.c b/formats/ctf/types/float.c index 0e4b9485..782f72bf 100644 --- a/formats/ctf/types/float.c +++ b/formats/ctf/types/float.c @@ -69,7 +69,7 @@ static struct declaration_float *static_float_declaration, *static_double_declaration; struct pos_len { - size_t sign_start, exp_start, mantissa_start, len; + size_t len; }; static void float_lock(void) diff --git a/types/float.c b/types/float.c index 3e49a4b1..b2ef65bc 100644 --- a/types/float.c +++ b/types/float.c @@ -83,7 +83,6 @@ struct definition * container_of(declaration, struct declaration_float, p); struct definition_float *_float; struct definition *tmp; - int ret; _float = g_new(struct definition_float, 1); declaration_ref(&float_declaration->p); @@ -121,6 +120,8 @@ struct definition * _float->p.name = field_name; _float->value = 0.0; if (parent_scope) { + int ret; + ret = register_field_definition(field_name, &_float->p, parent_scope); assert(!ret); diff --git a/types/types.c b/types/types.c index f74e730f..3ffe7e2f 100644 --- a/types/types.c +++ b/types/types.c @@ -117,10 +117,10 @@ static int compare_paths(GArray *a, GArray *b, int len) static int is_path_child_of(GArray *path, GArray *maybe_parent) { - int i, ret; + int ret; if (babeltrace_debug) { - int need_dot = 0; + int i, need_dot = 0; printf_debug("Is path \""); for (i = 0; i < path->len; need_dot = 1, i++) @@ -497,7 +497,6 @@ GQuark new_definition_path(struct definition_scope *parent_scope, GQuark path; GString *str; gchar *c_str; - int i; int need_dot = 0; str = g_string_new(""); @@ -505,6 +504,8 @@ GQuark new_definition_path(struct definition_scope *parent_scope, g_string_append(str, root_name); need_dot = 1; } else if (parent_scope) { + int i; + for (i = 0; i < parent_scope->scope_path->len; i++) { GQuark q = g_array_index(parent_scope->scope_path, GQuark, i); -- 2.34.1