From 74dc01d18ad1bf956b0ce48f20e66ecd542d20cd Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Thu, 7 Dec 2023 20:16:57 +0100 Subject: [PATCH] trace: fix coverity warnings (#1024) * trace: fix coverity warnings * trace: add RE_TRACE_ENABLED --- src/trace/trace.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/trace/trace.c b/src/trace/trace.c index 980d41860..832d0f977 100644 --- a/src/trace/trace.c +++ b/src/trace/trace.c @@ -46,6 +46,8 @@ #endif +#ifdef RE_TRACE_ENABLED + struct trace_event { const char *name; const char *cat; @@ -133,6 +135,7 @@ static void flush_tmr(void *arg) tmr_start(&trace.flush_tmr, TRACE_FLUSH_TMR, flush_tmr, NULL); } +#endif /** @@ -144,12 +147,9 @@ static void flush_tmr(void *arg) */ int re_trace_init(const char *json_file) { +#ifdef RE_TRACE_ENABLED int err = 0; -#ifndef RE_TRACE_ENABLED - return 0; -#endif - if (!json_file) return EINVAL; @@ -196,6 +196,10 @@ int re_trace_init(const char *json_file) } return err; +#else + (void)json_file; + return 0; +#endif } @@ -206,12 +210,9 @@ int re_trace_init(const char *json_file) */ int re_trace_close(void) { +#ifdef RE_TRACE_ENABLED int err = 0; -#ifndef RE_TRACE_ENABLED - return 0; -#endif - tmr_cancel(&trace.flush_tmr); re_trace_flush(); re_atomic_rlx_set(&trace.init, false); @@ -230,6 +231,9 @@ int re_trace_close(void) trace.f = NULL; return 0; +#else + return 0; +#endif } @@ -240,6 +244,7 @@ int re_trace_close(void) */ int re_trace_flush(void) { +#ifdef RE_TRACE_ENABLED int i, flush_count; struct trace_event *event_tmp; struct trace_event *e; @@ -247,10 +252,6 @@ int re_trace_flush(void) char name[128] = {0}; char id_str[128] = {0}; -#ifndef RE_TRACE_ENABLED - return 0; -#endif - if (!re_atomic_rlx(&trace.init)) return 0; @@ -311,6 +312,9 @@ int re_trace_flush(void) (void)fflush(trace.f); return 0; +#else + return 0; +#endif } @@ -318,12 +322,9 @@ void re_trace_event(const char *cat, const char *name, char ph, struct pl *id, re_trace_arg_type arg_type, const char *arg_name, void *arg_value) { +#ifdef RE_TRACE_ENABLED struct trace_event *e; -#ifndef RE_TRACE_ENABLED - return; -#endif - if (!re_atomic_rlx(&trace.init)) return; @@ -361,4 +362,13 @@ void re_trace_event(const char *cat, const char *name, char ph, struct pl *id, (const char *)arg_value); break; } +#else + (void)cat; + (void)name; + (void)ph; + (void)id; + (void)arg_type; + (void)arg_name; + (void)arg_value; +#endif }