Skip to content

Commit

Permalink
uftrace: Fix dead store warnings found by infer
Browse files Browse the repository at this point in the history
This patch fixes some dead store warnings found by a static analysis
tool, called infer[1].

The warning messages are as follows.

  $ cd /path/to/uftrace
  $ infer run --force-integration make
          ...
  #24
  utils/debug.c:386: error: Dead Store
    The value written to `&percent` (type `double`) is never used.
    384. void print_diff_percent(uint64_t base_nsec, uint64_t pair_nsec)
    385. {
    386. 	double percent = 999.99;
          ^

  #28
  utils/debug.c:387: error: Dead Store
    The value written to `&sc` is never used.
    385. {
    386.  double percent = 999.99;
    387.  const char *sc = get_color(COLOR_CODE_NORMAL);
          ^
    388.  const char *ec = get_color(COLOR_CODE_RESET);
    389.

  #31
  utils/kernel.c:57: error: Dead Store
    The value written to `&ret` is never used.
    55. {
    56.   struct kfilter *pos, *tmp;
    57.   int ret = -1;
         ^
    58.   int fd;
    59.

  #32
  utils/perf.c:230: error: Dead Store
    The value written to `&start` is never used.
    228.  buf = &data[start & mask];
    229.  size = end - start;
    230.  start += size;
          ^

And fix warning on compile time with including unistd.h
header file.

  utils/kernel-parser.c:151:9:
  warning: implicit declaration of function 'close';
  did you mean 'pclos'?
  [-Wimplicit-function-declaration]
    151 |         close(kp->fds[cpu]);
        |         ^~~~~
        |         pclose

[1] https://github.com/facebook/infer

Fixed: #1553
Signed-off-by: Paran Lee <p4ranlee@gmail.com>
  • Loading branch information
paranlee authored and yunse0ngkim committed Dec 10, 2023
1 parent 4213eb7 commit d756979
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 9 deletions.
8 changes: 3 additions & 5 deletions utils/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ void print_time_unit(uint64_t delta_nsec)

void print_diff_percent(uint64_t base_nsec, uint64_t pair_nsec)
{
double percent = 999.99;
const char *sc = get_color(COLOR_CODE_NORMAL);
double percent;
const char *sc;
const char *ec = get_color(COLOR_CODE_RESET);

if (base_nsec == 0) {
Expand All @@ -401,10 +401,8 @@ void print_diff_percent(uint64_t base_nsec, uint64_t pair_nsec)
percent = 100.0 * (int64_t)(pair_nsec - base_nsec) / base_nsec;

/* for some error cases */
if (percent > 999.99)
if (percent > 999.99 || percent < -999.99)
percent = 999.99;
else if (percent < -999.99)
percent = -999.99;

sc = percent > 30 ? get_color(COLOR_CODE_RED) :
percent > 3 ? get_color(COLOR_CODE_MAGENTA) :
Expand Down
1 change: 1 addition & 0 deletions utils/kernel-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>

/* This should be defined before #include "utils.h" */
#define PR_FMT "kernel"
Expand Down
4 changes: 1 addition & 3 deletions utils/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ struct kfilter {
static int set_filter_file(const char *filter_file, struct list_head *filters)
{
struct kfilter *pos, *tmp;
int ret = -1;
int fd;

fd = open_tracing_file(filter_file, true);
Expand All @@ -64,10 +63,9 @@ static int set_filter_file(const char *filter_file, struct list_head *filters)
if (write(fd, " ", 1) != 1)
pr_dbg2("writing filter file failed, but ignoring...\n");
}
ret = 0;

close(fd);
return ret;
return 0;
}

static int set_tracing_filter(struct uftrace_kernel_writer *kernel)
Expand Down
1 change: 0 additions & 1 deletion utils/perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ void record_perf_data(struct uftrace_perf_writer *perf, int cpu, int sock)

buf = &data[start & mask];
size = end - start;
start += size;

if (sock > 0)
send_trace_perf_data(sock, cpu, buf, size);
Expand Down

0 comments on commit d756979

Please sign in to comment.