Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code static checks infered by Infer(x86_64) #1553

Closed
paranlee opened this issue Aug 21, 2022 · 6 comments · Fixed by #1757
Closed

Code static checks infered by Infer(x86_64) #1553

paranlee opened this issue Aug 21, 2022 · 6 comments · Fixed by #1757
Labels

Comments

@paranlee
Copy link
Contributor

There are infering to improve the uftrace project codes from Facebook Infer.

Install and static analyze process

sudo apt -y install ocaml sqlite

git clone https://github.com/facebook/infer
cd infer
./build-infer.sh clang
## clang compile -> y
sudo make install

cd ~/uftrace
infer run --force-integration make

Result

Found 36 issues
          Issue Type(ISSUED_TYPE_ID): #
              Dead Store(DEAD_STORE): 27
  Null Dereference(NULL_DEREFERENCE): 5
        Resource Leak(RESOURCE_LEAK): 4

List

#0
cmds/dump.c:254: error: Dead Store
  The value written to `&end` (type `char*`) is never used.
  252. 				goto out;
  253. 			}
  254. 			*end++ = '\0';
           ^
  255. 
  256. 			pr_out("%s  session of task %d: %.*s (%s)\n", timestamp, tid, 16, sid,

#1
cmds/dump.c:735: error: Null Dereference
  pointer `event` last assigned on line 731 could be null and is dereferenced at line 735, column 2.
  733. 
  734. 	pr_time(frs->time);
  735. 	pr_out("%5d: [%s] %s:%s(%ld) %.*s\n", tid, rstack_type(frs), event->system, event->name,
        ^
  736. 	       frs->addr, size, event_data);
  737. 

#2
cmds/record.c:2081: error: Resource Leak
  resource acquired by call to `open()` at line 2072, column 14 is not released after line 2081, column 2.
  2079. 		pr_out("uftrace: install signal handlers to task %d\n", pid);
  2080. 
  2081. 	setup_writers(&wd, opts);
         ^
  2082. 	start_tracing(&wd, opts, ready);
  2083. 	close(ready);

#3
cmds/recv.c:266: error: Dead Store
  The value written to `&namelen` (type `int`) is never used.
  264. 		pr_err("map read failed");
  265. 
  266. 	namelen = htonl(namelen);
        ^
  267. 
  268. 	pr_dbg2("send UFTRACE_MSG_SEND_META_DATA: %s\n", filename);

#4
cmds/tui.c:1842: error: Dead Store
  The value written to `&len` (type `int`) is never used.
  1840. 	switch ((long)s) {
  1841. 	case TUI_SESS_REPORT:
  1842. 		print_buf(" R  Report functions");
          ^
  1843. 		break;
  1844. 	case TUI_SESS_INFO:

#5
cmds/tui.c:1845: error: Dead Store
  The value written to `&len` (type `int`) is never used.
  1843. 		break;
  1844. 	case TUI_SESS_INFO:
  1845. 		print_buf(" I  uftrace Info");
          ^
  1846. 		break;
  1847. 	case TUI_SESS_HELP:

#6
cmds/tui.c:1848: error: Dead Store
  The value written to `&len` (type `int`) is never used.
  1846. 		break;
  1847. 	case TUI_SESS_HELP:
  1848. 		print_buf(" h  Help message");
          ^
  1849. 		break;
  1850. 	case TUI_SESS_QUIT:

#7
cmds/tui.c:1851: error: Dead Store
  The value written to `&len` (type `int`) is never used.
  1849. 		break;
  1850. 	case TUI_SESS_QUIT:
  1851. 		print_buf(" q  quit");
          ^
  1852. 		break;
  1853. 	default:

#8
cmds/tui.c:1856: error: Dead Store
  The value written to `&len` (type `int`) is never used.
  1854. 		curr_sess = partial_graph.ug.sess;
  1855. 		get_current_graph(node, &count);
  1856. 		print_buf(" %c  %s #%d: %s", s == curr_sess ? 'G' : ' ', "call Graph for session",
          ^
  1857. 			  count, basename(s->exename));
  1858. 		break;

#9
cmds/tui.c:2702: error: Dead Store
  The value written to `&num_sort_key` (type `int`) is never used.
  2700. 	void *old_top;
  2701. 	enum tui_mode tui_mode;
  2702. 	int num_sort_key = 3;
         ^
  2703. 
  2704. 	graph = tui_graph_init(opts);

#10
cmds/tui.c:2779: error: Dead Store
  The value written to `&tui_mode` (type `int`) is never used.
  2777. 					break;
  2778. 				case TUI_SESS_QUIT:
  2779. 					tui_mode = TUI_MODE_OTHER;
             ^
  2780. 					goto out;
  2781. 				default:

#11
libmcount/dynamic.c:434: error: Dead Store
  The value written to `&delim` (type `char*`) is never used.
  432. 		else {
  433. 			*delim = '\0';
  434. 			pl->module = xstrdup(++delim);
                       ^
  435. 		}
  436. 

#12
libmcount/event.c:56: error: Dead Store
  The value written to `&ret` (type `int`) is never used.
  54. 	struct uftrace_elf_iter iter;
  55. 	bool found_sdt = false;
  56. 	int ret = -1;
       ^
  57. 
  58. 	if (name[0] == '\0')

#13
libmcount/mcount.c:1341: error: Null Dereference
  pointer `mtdp` last assigned on line 1339 could be null and is dereferenced at line 1341, column 2.
  1339. 	mtdp = get_thread_data();
  1340. 	ASSERT(mtdp != NULL);
  1341. 	ASSERT(!mtdp->dead);
         ^
  1342. 
  1343. 	/*

#14
libmcount/plthook.c:927: error: Null Dereference
  pointer `mtdp` last assigned on line 919 could be null and is dereferenced by call to `__mcount_guard_recursion()` at line 927, column 2.
  925. 	 * prevent recursion during this call.
  926. 	 */
  927. 	__mcount_guard_recursion(mtdp);
        ^
  928. 
  929. again:

#15
libmcount/record.c:1176: error: Dead Store
  The value written to `&prev_written` (type `_Bool`) is never used.
  1174. 				write_map(ofp, prev_map, prev_major, prev_minor, prev_ino,
  1175. 					  prev_off);
  1176. 				prev_written = true;
            ^
  1177. 			}
  1178. 		}

#16
libmcount/record.c:1193: error: Dead Store
  The value written to `&prev_off` (type `unsigned long`) is never used.
  1191. 		map->next = NULL;
  1192. 		prev_map = map;
  1193. 		prev_off = off;
          ^
  1194. 		prev_ino = ino;
  1195. 		prev_major = major;

#17
libmcount/record.c:1194: error: Dead Store
  The value written to `&prev_ino` (type `unsigned int`) is never used.
  1192. 		prev_map = map;
  1193. 		prev_off = off;
  1194. 		prev_ino = ino;
          ^
  1195. 		prev_major = major;
  1196. 		prev_minor = minor;

#18
libmcount/record.c:1195: error: Dead Store
  The value written to `&prev_major` (type `unsigned char`) is never used.
  1193. 		prev_off = off;
  1194. 		prev_ino = ino;
  1195. 		prev_major = major;
          ^
  1196. 		prev_minor = minor;
  1197. 		prev_written = false;

#19
libmcount/record.c:1196: error: Dead Store
  The value written to `&prev_minor` (type `unsigned char`) is never used.
  1194. 		prev_ino = ino;
  1195. 		prev_major = major;
  1196. 		prev_minor = minor;
          ^
  1197. 		prev_written = false;
  1198. 	}

#20
libtraceevent/event-parse.c:3681: error: Dead Store
  The value written to `&str` (type `char*`) is never used.
  3679. 			field = pevent_find_any_field(event, arg->field.name);
  3680. 			if (!field) {
  3681. 				str = arg->field.name;
            ^
  3682. 				goto out_warning_field;
  3683. 			}

#21
libtraceevent/event-plugin.c:265: error: Dead Store
  The value written to `&alias` (type `char const *`) is never used.
  263. 	alias = dlsym(handle, PEVENT_PLUGIN_ALIAS_NAME);
  264. 	if (!alias)
  265. 		alias = file;
         ^
  266. 
  267. 	func = dlsym(handle, PEVENT_PLUGIN_LOADER_NAME);

#22
libtraceevent/parse-filter.c:1283: error: Dead Store
  The value written to `&len` (type `int`) is never used.
  1281. 	filter_start = strchr(filter_str, ':');
  1282. 	if (filter_start)
  1283. 		len = filter_start - filter_str;
          ^
  1284. 	else
  1285. 		len = strlen(filter_str);

#23
libtraceevent/parse-filter.c:1285: error: Dead Store
  The value written to `&len` (type `int`) is never used.
  1283. 		len = filter_start - filter_str;
  1284. 	else
  1285. 		len = strlen(filter_str);
          ^
  1286. 
  1287. 	do {

#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;
        ^
  387. 	const char *sc = get_color(COLOR_CODE_NORMAL);
  388. 	const char *ec = get_color(COLOR_CODE_RESET);

#25
utils/debug.c:387: error: Dead Store
  The value written to `&sc` (type `char const *`) 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. 

#26
utils/fstack.c:478: error: Dead Store
  The value written to `&or` (type `char*`) is never used.
  476. 			if (opts->hide) {
  477. 				pr_out("%s%s", or, opts->hide);
  478. 				or = " or ";
           ^
  479. 			}
  480. 			pr_out("\n");

#27
utils/fstack.c:1902: error: Dead Store
  The value written to `&cpu` (type `int`) is never used.
  1900. static int find_rstack_cpu(struct uftrace_kernel_reader *kernel, struct uftrace_record *rstack)
  1901. {
  1902. 	int cpu = -1;
         ^
  1903. 
  1904. 	if (rstack->type == UFTRACE_LOST) {

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

#29
utils/kernel.c:130: error: Null Dereference
  pointer `filename` last assigned on line 128 could be null and is dereferenced by call to `access()` at line 130, column 7.
  128. 	char *filename = get_tracing_file("options/function-fork");
  129. 
  130. 	if (!access(filename, F_OK))
             ^
  131. 		ret = false;
  132. 

#30
utils/perf.c:230: error: Dead Store
  The value written to `&start` (type `unsigned long`) is never used.
  228. 	buf = &data[start & mask];
  229. 	size = end - start;
  230. 	start += size;
        ^
  231. 
  232. 	if (sock > 0)

#31
utils/script.c:48: error: Null Dereference
  pointer `ext` last assigned on line 42 could be null and is dereferenced by call to `strcmp()` at line 48, column 7.
  46. 	 * As of now, it only handles ".py" suffix for python.
  47. 	 */
  48. 	if (!strcmp(ext, ".py"))
            ^
  49. 		return SCRIPT_PYTHON;
  50. 	else if (!strcmp(ext, ".lua"))

#32
utils/symbol.c:654: error: Resource Leak
  resource acquired to `elf.fd` by call to `elf_init()` at line 648, column 6 is not released after line 654, column 8.
  652. 
  653. 	pr_dbg3("loading dynamic symbols from %s (offset: %#lx)\n", filename, offset);
  654. 	ret = load_elf_dynsymtab(dsymtab, &elf, offset, flags);
              ^
  655. 
  656. 	elf_finish(&elf);

#33
utils/symbol.c:716: error: Dead Store
  The value written to `&ret` (type `int`) is never used.
  714. 				      unsigned long offset, unsigned long flags)
  715. {
  716. 	int ret = -1;
        ^
  717. 	int count = 0;
  718. 	struct uftrace_elf_data elf;

#34
utils/tracefs.c:41: error: Resource Leak
  resource of type `_IO_FILE` acquired by call to `fopen()` at line 23, column 7 is not released after line 41, column 8.
  39. 		if (!strcmp(fs_type, "tracefs")) {
  40. 			/* discard previously kept debugfs tracing dir */
  41. 			if (TRACING_DIR)
             ^
  42. 				free(TRACING_DIR);
  43. 			xasprintf(&TRACING_DIR, "%s", mount_point);

#35
utils/tracefs.c:42: error: Resource Leak
  resource of type `_IO_FILE` acquired by call to `fopen()` at line 23, column 7 is not released after line 42, column 10.
  40. 			/* discard previously kept debugfs tracing dir */
  41. 			if (TRACING_DIR)
  42. 				free(TRACING_DIR);
               ^
  43. 			xasprintf(&TRACING_DIR, "%s", mount_point);
  44. 			pr_dbg2("Found tracefs at %s\n", mount_point);
@namhyung
Copy link
Owner

Interesting. Do they have GitHub actions?

@paranlee
Copy link
Contributor Author

paranlee commented Sep 4, 2022

If the infer execution environment is prepared in the image to be used for github CI/CD, it seems possible.

Facebook Infer Github Action workflow

Local Docker Image

paranlee added a commit to paranlee/uftrace that referenced this issue Sep 4, 2022
issue namhyung#1553 related Null dereference amend works.

Signed-off-by: Paran Lee <p4ranlee@gmail.com>
@paranlee
Copy link
Contributor Author

paranlee commented Sep 4, 2022

Add Null Checks in issue #1567 utils: Null dereference amend

I try to divide the PR between the clean up works and modifying the logic while refactoring.

@paranlee paranlee changed the title Code static checks infered by Infer Code static checks infered by Infer(x86_64) Sep 7, 2022
@paranlee
Copy link
Contributor Author

Install ocaml with with ocaml package manager

paranlee added a commit to paranlee/uftrace that referenced this issue Sep 16, 2022
issue namhyung#1553 related Null dereference amend works.

Signed-off-by: Paran Lee <p4ranlee@gmail.com>
paranlee added a commit to paranlee/uftrace that referenced this issue Sep 16, 2022
issue namhyung#1553 related Null dereference amend works.

Signed-off-by: Paran Lee <p4ranlee@gmail.com>
namhyung pushed a commit that referenced this issue Sep 24, 2022
issue #1553 related Null dereference amend works.

Signed-off-by: Paran Lee <p4ranlee@gmail.com>
dongwooklee96 pushed a commit to dongwooklee96/uftrace that referenced this issue Oct 14, 2022
issue namhyung#1553 related Null dereference amend works.

Signed-off-by: Paran Lee <p4ranlee@gmail.com>
dongwooklee96 pushed a commit to dongwooklee96/uftrace that referenced this issue Oct 14, 2022
issue namhyung#1553 related Null dereference amend works.

Signed-off-by: Paran Lee <p4ranlee@gmail.com>
dongwooklee96 pushed a commit to dongwooklee96/uftrace that referenced this issue Oct 14, 2022
issue namhyung#1553 related Null dereference amend works.

Signed-off-by: Paran Lee <p4ranlee@gmail.com>
dongwooklee96 pushed a commit to dongwooklee96/uftrace that referenced this issue Oct 14, 2022
issue namhyung#1553 related Null dereference amend works.

Signed-off-by: Paran Lee <p4ranlee@gmail.com>
@paranlee
Copy link
Contributor Author

paranlee commented Jul 3, 2023

Do Infer with 6721fec.

#0
arch/x86_64/mcount-dynamic.c:182: error: Resource Leak
  resource acquired to `elf.fd` by call to `elf_init()` at line 174, column 6 is not released after line 182, column 4.
  180.          if (!strcmp(shstr, PATCHABLE_SECT)) {
  181.                  mdi->type = DYNAMIC_PATCHABLE;
  182.                  read_patchable_loc(mdi, &elf, &iter, mdi->base_addr);
          ^
  183.                  goto out;
  184.          }

#1
arch/x86_64/mcount-dynamic.c:188: error: Resource Leak
  resource acquired to `elf.fd` by call to `elf_init()` at line 174, column 6 is not released after line 188, column 4.
  186.          if (!strcmp(shstr, XRAY_SECT)) {
  187.                  mdi->type = DYNAMIC_XRAY;
  188.                  read_xray_map(mdi, &elf, &iter, mdi->base_addr);
          ^
  189.                  goto out;
  190.          }

#2
arch/x86_64/mcount-dynamic.c:193: error: Resource Leak
  resource acquired to `elf.fd` by call to `elf_init()` at line 174, column 6 is not released after line 193, column 4.
  191.
  192.          if (!strcmp(shstr, MCOUNTLOC_SECT)) {
  193.                  read_mcount_loc(mdi, &elf, &iter, mdi->base_addr);
          ^
  194.                  /* still needs to check pg or fentry */
  195.          }

#3
cmds/graph.c:282: error: Null Dereference
  pointer `graph` last assigned on line 279 could be null and is dereferenced at line 282, column 3.
  280.
  281.  if (tg->utg.graph && tg->utg.graph != graph) {
  282.          pr_dbg("detect new session: %.*s\n", SESSION_ID_LEN, graph->sess->sid);
         ^
  283.          tg->utg.new_sess = true;
  284.  }

#4
cmds/record.c:2108: error: Resource Leak
  resource acquired by call to `open()` at line 2099, column 14 is not released after line 2108, column 2.
  2106.                 pr_out("uftrace: install signal handlers to task %d\n", pid);
  2107.
  2108.         setup_writers(&wd, opts);
         ^
  2109.         start_tracing(&wd, opts, ready);
  2110.         close(ready);

#5
cmds/recv.c:288: error: Dead Store
  The value written to `&namelen` is never used.
  286.          pr_err("map read failed");
  287.
  288.  namelen = htonl(namelen);
        ^
  289.
  290.  pr_dbg2("send UFTRACE_MSG_SEND_META_DATA: %s\n", filename);

#6
cmds/tui.c:1859: error: Dead Store
  The value written to `&len` is never used.
  1857.         switch ((long)s) {
  1858.         case TUI_SESS_REPORT:
  1859.                 print_buf(" R  Report functions");
          ^
  1860.                 break;
  1861.         case TUI_SESS_INFO:

#7
cmds/tui.c:1862: error: Dead Store
  The value written to `&len` is never used.
  1860.                 break;
  1861.         case TUI_SESS_INFO:
  1862.                 print_buf(" I  uftrace Info");
          ^
  1863.                 break;
  1864.         case TUI_SESS_HELP:

#8
cmds/tui.c:1865: error: Dead Store
  The value written to `&len` is never used.
  1863.                 break;
  1864.         case TUI_SESS_HELP:
  1865.                 print_buf(" h  Help message");
          ^
  1866.                 break;
  1867.         case TUI_SESS_QUIT:

#9
cmds/tui.c:1868: error: Dead Store
  The value written to `&len` is never used.
  1866.                 break;
  1867.         case TUI_SESS_QUIT:
  1868.                 print_buf(" q  quit");
          ^
  1869.                 break;
  1870.         default:

#10
cmds/tui.c:1873: error: Dead Store
  The value written to `&len` is never used.
  1871.                 curr_sess = partial_graph.ug.sess;
  1872.                 get_current_graph(node, &count);
  1873.                 print_buf(" %c  %s #%d: %s", s == curr_sess ? 'G' : ' ', "call Graph for session",
          ^
  1874.                           count, basename(s->exename));
  1875.                 break;

#11
cmds/tui.c:2719: error: Dead Store
  The value written to `&num_sort_key` is never used.
  2717.         void *old_top;
  2718.         enum tui_mode tui_mode;
  2719.         int num_sort_key = 3;
         ^
  2720.
  2721.         graph = tui_graph_init(opts);

#12
cmds/tui.c:2796: error: Dead Store
  The value written to `&tui_mode` is never used.
  2794.                                         break;
  2795.                                 case TUI_SESS_QUIT:
  2796.                                         tui_mode = TUI_MODE_OTHER;
             ^
  2797.                                         goto out;
  2798.                                 default:

#13
libmcount/dynamic.c:435: error: Dead Store
  The value written to `&delim` is never used.
  433.          else {
  434.                  *delim = '\0';
  435.                  pl->module = xstrdup(++delim);
                       ^
  436.          }
  437.

#14
libmcount/event.c:56: error: Dead Store
  The value written to `&ret` is never used.
  54.   struct uftrace_elf_iter iter;
  55.   bool found_sdt = false;
  56.   int ret = -1;
       ^
  57.
  58.   if (name[0] == '\0')

#15
libmcount/mcount.c:1424: error: Null Dereference
  pointer `mtdp` last assigned on line 1422 could be null and is dereferenced at line 1424, column 2.
  1422.         mtdp = get_thread_data();
  1423.         ASSERT(mtdp != NULL);
  1424.         ASSERT(!mtdp->dead);
         ^
  1425.
  1426.         /*

#16
libmcount/mcount.c:1917: error: Null Dereference
  pointer `*value` last assigned on line 1913 could be null and is dereferenced by call to `read_all()` at line 1917, column 6.
  1915.                 return -1;
  1916.
  1917.         if (read_all(fd, *value, value_size) < 0)
             ^
  1918.                 return -1;
  1919.

#17
libmcount/plthook.c:936: error: Null Dereference
  pointer `mtdp` last assigned on line 928 could be null and is dereferenced by call to `__mcount_guard_recursion()` at line 936, column 2.
  934.   * prevent recursion during this call.
  935.   */
  936.  __mcount_guard_recursion(mtdp);
        ^
  937.
  938. again:

#18
libmcount/record.c:1182: error: Dead Store
  The value written to `&prev_written` is never used.
  1180.                                 write_map(ofp, prev_map, prev_major, prev_minor, prev_ino,
  1181.                                           prev_off);
  1182.                                 prev_written = true;
            ^
  1183.                         }
  1184.                 }

#19
libmcount/record.c:1199: error: Dead Store
  The value written to `&prev_off` is never used.
  1197.                 map->next = NULL;
  1198.                 prev_map = map;
  1199.                 prev_off = off;
          ^
  1200.                 prev_ino = ino;
  1201.                 prev_major = major;

#20
libmcount/record.c:1200: error: Dead Store
  The value written to `&prev_ino` is never used.
  1198.                 prev_map = map;
  1199.                 prev_off = off;
  1200.                 prev_ino = ino;
          ^
  1201.                 prev_major = major;
  1202.                 prev_minor = minor;

#21
libmcount/record.c:1201: error: Dead Store
  The value written to `&prev_major` is never used.
  1199.                 prev_off = off;
  1200.                 prev_ino = ino;
  1201.                 prev_major = major;
          ^
  1202.                 prev_minor = minor;
  1203.                 prev_written = false;

#22
libmcount/record.c:1202: error: Dead Store
  The value written to `&prev_minor` is never used.
  1200.                 prev_ino = ino;
  1201.                 prev_major = major;
  1202.                 prev_minor = minor;
          ^
  1203.                 prev_written = false;
  1204.         }

#23
libtraceevent/event-parse.c:3681: error: Dead Store
  The value written to `&str` is never used.
  3679.                         field = pevent_find_any_field(event, arg->field.name);
  3680.                         if (!field) {
  3681.                                 str = arg->field.name;
            ^
  3682.                                 goto out_warning_field;
  3683.                         }

#24
libtraceevent/event-plugin.c:265: error: Dead Store
  The value written to `&alias` is never used.
  263.  alias = dlsym(handle, PEVENT_PLUGIN_ALIAS_NAME);
  264.  if (!alias)
  265.          alias = file;
         ^
  266.
  267.  func = dlsym(handle, PEVENT_PLUGIN_LOADER_NAME);

#25
libtraceevent/parse-filter.c:1283: error: Dead Store
  The value written to `&len` is never used.
  1281.         filter_start = strchr(filter_str, ':');
  1282.         if (filter_start)
  1283.                 len = filter_start - filter_str;
          ^
  1284.         else
  1285.                 len = strlen(filter_str);

#26
libtraceevent/parse-filter.c:1285: error: Dead Store
  The value written to `&len` is never used.
  1283.                 len = filter_start - filter_str;
  1284.         else
  1285.                 len = strlen(filter_str);
          ^
  1286.
  1287.         do {

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

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

#29
utils/fstack.c:540: error: Dead Store
  The value written to `&or` is never used.
  538.                  if (opts->loc_filter) {
  539.                          pr_out("%s%s", or, opts->loc_filter);
  540.                          or = " or ";
           ^
  541.                  }
  542.                  pr_out("\n");

#30
utils/fstack.c:2038: error: Dead Store
  The value written to `&cpu` is never used.
  2036. static int find_rstack_cpu(struct uftrace_kernel_reader *kernel, struct uftrace_record *rstack)
  2037. {
  2038.         int cpu = -1;
         ^
  2039.
  2040.         if (rstack->type == UFTRACE_LOST) {

#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;
        ^
  231.
  232.  if (sock > 0)

#33
utils/symbol.c:658: error: Resource Leak
  resource acquired to `elf.fd` by call to `elf_init()` at line 652, column 6 is not released after line 658, column 8.
  656.
  657.  pr_dbg3("loading dynamic symbols from %s (offset: %#lx)\n", filename, offset);
  658.  ret = load_elf_dynsymtab(dsymtab, &elf, offset, flags);
              ^
  659.
  660.  elf_finish(&elf);

#34
utils/symbol.c:720: error: Dead Store
  The value written to `&ret` is never used.
  718.                                unsigned long offset, unsigned long flags)
  719. {
  720.  int ret = -1;
        ^
  721.  int count = 0;
  722.  struct uftrace_elf_data elf;

#35
utils/tracefs.c:41: error: Resource Leak
  resource of type `_IO_FILE` acquired by call to `fopen()` at line 23, column 7 is not released after line 41, column 8.
  39.           if (!strcmp(fs_type, "tracefs")) {
  40.                   /* discard previously kept debugfs tracing dir */
  41.                   if (TRACING_DIR)
             ^
  42.                           free(TRACING_DIR);
  43.                   xasprintf(&TRACING_DIR, "%s", mount_point);

#36
utils/tracefs.c:42: error: Resource Leak
  resource of type `_IO_FILE` acquired by call to `fopen()` at line 23, column 7 is not released after line 42, column 10.
  40.                   /* discard previously kept debugfs tracing dir */
  41.                   if (TRACING_DIR)
  42.                           free(TRACING_DIR);
               ^
  43.                   xasprintf(&TRACING_DIR, "%s", mount_point);
  44.                   pr_dbg2("Found tracefs at %s\n", mount_point);

#37
utils/tracefs.c:63: error: Resource Leak
  resource of type `_IO_FILE` acquired by call to `fopen()` at line 23, column 7 is not released after line 63, column 2.
  61.   }
  62.
  63.   pr_dbg2("No tracefs or debugfs found..!\n");
       ^
  64.   return false;
  65. }

Found 38 issues
          Issue Type(ISSUED_TYPE_ID): #
              Dead Store(DEAD_STORE): 26
        Resource Leak(RESOURCE_LEAK): 8
  Null Dereference(NULL_DEREFERENCE): 4

paranlee added a commit to paranlee/uftrace that referenced this issue Jul 12, 2023
Issue namhyung#1553 related ret variable dead store clean up.

Signed-off-by: Paran Lee <p4ranlee@gmail.com>
paranlee added a commit to paranlee/uftrace that referenced this issue Jul 12, 2023
issue namhyung#1553 related Dead Store clean up.

Signed-off-by: Paran Lee <p4ranlee@gmail.com>
@MichelleJin12
Copy link
Contributor

MichelleJin12 commented Jul 15, 2023

According to https://github.com/facebook/infer/blob/main/INSTALL.md#infer-dependencies-for-linux,

sudo apt install -y opam pkg-config gcc clang autoconf automake cmake
./build-infer.sh clang
sudo make install

or

./autogen.sh
./configure # Disable Java or C/C++/ObjC analyzers with --disable-java-analyzers or --disable-c-analyzers
make
# install Infer system-wide...
sudo make install
# ...or, alternatively, install Infer into your PATH
export PATH=`pwd`/infer/bin:$PATH

paranlee added a commit to paranlee/uftrace that referenced this issue Aug 15, 2023
Issue namhyung#1553 related ret variable dead store clean up.

Signed-off-by: Paran Lee <p4ranlee@gmail.com>

debug: refactor not needed initialization

Not needed initialization on double variable.

Signed-off-by: Paran Lee <p4ranlee@gmail.com>
paranlee added a commit to paranlee/uftrace that referenced this issue Aug 15, 2023
Issue namhyung#1553 related ret variable dead store clean up.

Not needed initialization on double variable.

Signed-off-by: Paran Lee <p4ranlee@gmail.com>
paranlee added a commit to paranlee/uftrace that referenced this issue Aug 15, 2023
Remove Not needed initialization on double variable.
Fixed: namhyung#1553

Signed-off-by: Paran Lee <p4ranlee@gmail.com>
paranlee pushed a commit to paranlee/uftrace that referenced this issue Dec 10, 2023
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
          ...
  namhyung#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;
          ^

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

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

  namhyung#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: namhyung#1553
Signed-off-by: Paran Lee <p4ranlee@gmail.com>
paranlee added a commit to paranlee/uftrace that referenced this issue Dec 10, 2023
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
          ...
  namhyung#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;
          ^

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

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

  namhyung#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: namhyung#1553
Signed-off-by: Paran Lee <p4ranlee@gmail.com>
paranlee added a commit to paranlee/uftrace that referenced this issue Dec 10, 2023
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
          ...
  namhyung#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;
          ^

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

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

  namhyung#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: namhyung#1553
Signed-off-by: Paran Lee <p4ranlee@gmail.com>
paranlee added a commit to paranlee/uftrace that referenced this issue Dec 14, 2023
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
Signed-off-by: Paran Lee <p4ranlee@gmail.com>
paranlee added a commit to paranlee/uftrace that referenced this issue Dec 14, 2023
 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
Signed-off-by: Paran Lee <p4ranlee@gmail.com>
paranlee pushed a commit to paranlee/uftrace that referenced this issue Dec 14, 2023
 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>
paranlee pushed a commit to paranlee/uftrace that referenced this issue Dec 14, 2023
 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>
paranlee added a commit to paranlee/uftrace that referenced this issue Dec 14, 2023
 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>
paranlee added a commit to paranlee/uftrace that referenced this issue Dec 16, 2023
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;
          ^

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

Fixed: namhyung#1553
Signed-off-by: Paran Lee <p4ranlee@gmail.com>
namhyung pushed a commit that referenced this issue Dec 17, 2023
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;
          ^

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

Fixed: #1553
Signed-off-by: Paran Lee <p4ranlee@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants