Skip to content

Commit

Permalink
uftrace: Fix dead store warnings found by infer and
Browse files Browse the repository at this point in the history
 warning on compile time implicit declaration

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
          ...

  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;
          ^

  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.

  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.

  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: namhyung#1553, namhyung#1859
Signed-off-by: Paran Lee <p4ranlee@gmail.com>
  • Loading branch information
yunse0ngkim committed Dec 14, 2023
1 parent ced96bb commit b686c13
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 6 deletions.
4 changes: 2 additions & 2 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 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 b686c13

Please sign in to comment.