Skip to content

Commit

Permalink
trace: fix coverity warnings (#1024)
Browse files Browse the repository at this point in the history
* trace: fix coverity warnings

* trace: add RE_TRACE_ENABLED
  • Loading branch information
alfredh authored Dec 7, 2023
1 parent cbcabbc commit 74dc01d
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions src/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
#endif


#ifdef RE_TRACE_ENABLED

struct trace_event {
const char *name;
const char *cat;
Expand Down Expand Up @@ -133,6 +135,7 @@ static void flush_tmr(void *arg)

tmr_start(&trace.flush_tmr, TRACE_FLUSH_TMR, flush_tmr, NULL);
}
#endif


/**
Expand All @@ -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;

Expand Down Expand Up @@ -196,6 +196,10 @@ int re_trace_init(const char *json_file)
}

return err;
#else
(void)json_file;
return 0;
#endif
}


Expand All @@ -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);
Expand All @@ -230,6 +231,9 @@ int re_trace_close(void)
trace.f = NULL;

return 0;
#else
return 0;
#endif
}


Expand All @@ -240,17 +244,14 @@ 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;
char json_arg[256] = {0};
char name[128] = {0};
char id_str[128] = {0};

#ifndef RE_TRACE_ENABLED
return 0;
#endif

if (!re_atomic_rlx(&trace.init))
return 0;

Expand Down Expand Up @@ -311,19 +312,19 @@ int re_trace_flush(void)

(void)fflush(trace.f);
return 0;
#else
return 0;
#endif
}


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;

Expand Down Expand Up @@ -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
}

0 comments on commit 74dc01d

Please sign in to comment.