diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2023-11-13 13:52:42 +0100 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2023-11-13 13:52:42 +0100 |
commit | 82934b7271ad11332cdc291188e6b51e9534c301 (patch) | |
tree | 6f48d177a1a047878c54db75b9945aa0e3242eea | |
parent | 4920b2a4be62b85b6355278fe0d63637bddb624f (diff) |
Fixed clang-tidy warnings.
* fixed/improved c-captured logging
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r-- | examples/c-captured/c-captured.c | 6 | ||||
-rw-r--r-- | examples/c-json-stdout/c-json-stdout.c | 5 | ||||
-rw-r--r-- | examples/c-simple/c-simple.c | 2 | ||||
-rw-r--r-- | nDPId-test.c | 12 | ||||
-rw-r--r-- | nDPId.c | 12 |
5 files changed, 19 insertions, 18 deletions
diff --git a/examples/c-captured/c-captured.c b/examples/c-captured/c-captured.c index 338125b6f..9356db8f5 100644 --- a/examples/c-captured/c-captured.c +++ b/examples/c-captured/c-captured.c @@ -952,7 +952,7 @@ static enum nDPIsrvd_callback_return captured_json_callback(struct nDPIsrvd_sock if (flow_user->packets == NULL || flow_user->flow_max_packets == 0 || utarray_len(flow_user->packets) == 0) { - if (logging_mode != 0) + if (capture_mode != 0) { logger(0, "Flow %llu: No packets captured.", flow->id_as_ull); } @@ -1335,8 +1335,8 @@ int main(int argc, char ** argv) return 1; } - logger(0, "Recv buffer size: %u\n", NETWORK_BUFFER_MAX_SIZE); - logger(0, "Connecting to `%s'..\n", serv_optarg); + logger(0, "Recv buffer size: %u", NETWORK_BUFFER_MAX_SIZE); + logger(0, "Connecting to `%s'..", serv_optarg); if (nDPIsrvd_connect(sock) != CONNECT_OK) { diff --git a/examples/c-json-stdout/c-json-stdout.c b/examples/c-json-stdout/c-json-stdout.c index ae082a366..a80369c82 100644 --- a/examples/c-json-stdout/c-json-stdout.c +++ b/examples/c-json-stdout/c-json-stdout.c @@ -90,8 +90,7 @@ int main(void) break; } - if (buf[json_bytes - 2] != '}' || - buf[json_bytes - 1] != '\n') + if (buf[json_bytes - 2] != '}' || buf[json_bytes - 1] != '\n') { fprintf(stderr, "BUG: Invalid JSON string: \"%.*s\"\n", (int)json_bytes, buf); exit(1); @@ -129,8 +128,6 @@ int main(void) memmove(buf, buf + json_bytes, buf_used - json_bytes); buf_used -= json_bytes; - json_bytes = 0; - json_start = 0; } } diff --git a/examples/c-simple/c-simple.c b/examples/c-simple/c-simple.c index 642611f07..29321c963 100644 --- a/examples/c-simple/c-simple.c +++ b/examples/c-simple/c-simple.c @@ -58,7 +58,7 @@ static void nDPIsrvd_write_flow_info_cb(struct nDPIsrvd_socket const * sock, #endif flow->last_seen, flow->idle_time, - (flow->last_seen + flow->idle_time >= thread_data->most_recent_flow_time + (thread_data != NULL && flow->last_seen + flow->idle_time >= thread_data->most_recent_flow_time ? flow->last_seen + flow->idle_time - thread_data->most_recent_flow_time : 0)); } diff --git a/nDPId-test.c b/nDPId-test.c index 8f69350f9..f5c6a7ed7 100644 --- a/nDPId-test.c +++ b/nDPId-test.c @@ -479,7 +479,7 @@ static enum nDPIsrvd_callback_return update_flow_packets_processed(struct nDPIsr return CALLBACK_ERROR; } - if (sock->flow_user_data_size > 0) + if (flow_stats != NULL && sock->flow_user_data_size > 0) { flow_stats->total_packets_processed = 0; } @@ -513,7 +513,7 @@ static enum nDPIsrvd_callback_return update_flow_l4_payload_len(struct nDPIsrvd_ struct nDPIsrvd_json_token const * const flow_total_l4_payload_len[FD_COUNT] = { TOKEN_GET_SZ(sock, "flow_src_tot_l4_payload_len"), TOKEN_GET_SZ(sock, "flow_dst_tot_l4_payload_len")}; - if (sock->flow_user_data_size > 0) + if (flow_stats != NULL && sock->flow_user_data_size > 0) { flow_stats->flow_total_l4_data_len = 0; } @@ -586,7 +586,7 @@ static enum nDPIsrvd_callback_return distributor_json_callback(struct nDPIsrvd_s { instance_stats->daemon_event_count++; } - if (sock->thread_user_data_size > 0) + if (thread_stats != NULL && sock->thread_user_data_size > 0) { thread_stats->daemon_event_count++; } @@ -687,7 +687,7 @@ static enum nDPIsrvd_callback_return distributor_json_callback(struct nDPIsrvd_s { global_stats->cur_active_flows++; global_stats->flow_new_count++; - if (sock->thread_user_data_size > 0) + if (thread_stats != NULL && sock->thread_user_data_size > 0) { thread_stats->flow_new_count++; } @@ -707,7 +707,7 @@ static enum nDPIsrvd_callback_return distributor_json_callback(struct nDPIsrvd_s global_stats->cur_active_flows--; global_stats->cur_idle_flows++; global_stats->flow_end_count++; - if (sock->thread_user_data_size > 0) + if (thread_stats != NULL && sock->thread_user_data_size > 0) { thread_stats->flow_end_count++; } @@ -723,7 +723,7 @@ static enum nDPIsrvd_callback_return distributor_json_callback(struct nDPIsrvd_s global_stats->cur_active_flows--; global_stats->cur_idle_flows++; global_stats->flow_idle_count++; - if (sock->thread_user_data_size > 0) + if (thread_stats != NULL && sock->thread_user_data_size > 0) { thread_stats->flow_idle_count++; } @@ -361,7 +361,7 @@ enum error_event IP4_PACKET_TOO_SHORT, IP4_SIZE_SMALLER_THAN_HEADER, IP4_L4_PAYLOAD_DETECTION_FAILED, - IP6_PACKET_TOO_SHORT, + IP6_PACKET_TOO_SHORT, // 10 IP6_SIZE_SMALLER_THAN_HEADER, IP6_L4_PAYLOAD_DETECTION_FAILED, TCP_PACKET_TOO_SHORT, @@ -370,7 +370,7 @@ enum error_event MAX_FLOW_TO_TRACK, FLOW_MEMORY_ALLOCATION_FAILED, - ERROR_EVENT_COUNT + ERROR_EVENT_COUNT // 17 }; enum daemon_event @@ -1511,7 +1511,10 @@ static void free_workflow(struct nDPId_workflow ** const workflow) } for (size_t i = 0; i < w->max_active_flows; i++) { - ndpi_tdestroy(w->ndpi_flows_active[i], ndpi_flow_info_free); + if (w->ndpi_flows_active != NULL) + { + ndpi_tdestroy(w->ndpi_flows_active[i], ndpi_flow_info_free); + } } ndpi_free(w->ndpi_flows_active); ndpi_free(w->ndpi_flows_idle); @@ -4826,7 +4829,8 @@ static int stop_reader_threads(void) reader_threads[i].workflow->total_flow_updates); } /* total packets captured: same value for all threads as packet2thread distribution happens later */ - printf("Total packets captured.......: %llu\n", reader_threads[0].workflow->packets_captured); + printf("Total packets captured.......: %llu\n", + (reader_threads[0].workflow != NULL ? reader_threads[0].workflow->packets_captured : 0)); printf("Total packets processed......: %llu\n", total_packets_processed); printf("Total layer4 payload size....: %llu\n", total_l4_payload_len); printf("Total flows ignopred.........: %llu\n", total_flows_skipped); |