unit icon indicating copy to clipboard operation
unit copied to clipboard

Suggestion: Use GCC-12 with -fanalyzer for tests

Open vt-alt opened this issue 3 years ago • 2 comments

If you have CI please use gcc-12 with -fanalyzer option to find potential bugs. (Many major distro already have gcc-12). For example, there are such warnings currently in 1.27.0:

src/nxt_isolation.c: In function 'nxt_isolation_make_private_mount':
src/nxt_isolation.c:891:9: error: leak of 'strdup(*ent.mnt_dir)' [CWE-401] [-Werror=analyzer-malloc-leak]
  891 |         shared[index] = hasmntopt(ent, "shared") != NULL;
      |         ^~~~~~

src/nxt_router.c: In function 'nxt_router_listen_socket_update':
src/nxt_router.c:3503:17: error: dereference of NULL '0' [CWE-476] [-Werror=analyzer-null-dereference]
 3503 |     lev->listen = joint->socket_conf->listen;
      |     ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/nxt_router.c: In function 'nxt_router_listen_socket_update':
src/nxt_router.c:3503:17: error: dereference of NULL '0' [CWE-476] [-Werror=analyzer-null-dereference]
 3503 |     lev->listen = joint->socket_conf->listen;
      |     ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'nxt_unit_mmap_buf_unlink',
    inlined from 'nxt_unit_mmap_buf_release' at src/nxt_unit.c:2469:5:
src/nxt_unit.c:816:10: error: use of uninitialized value 'mmap_buf_7(D)->prev' [CWE-457] [-Werror=analyzer-use-of-uninitialized-value]
  816 |     prev = mmap_buf->prev;
      |     ~~~~~^~~~~~~~~~~~~~~~

[Last one if building with LTO (-flto -ffat-lto-objects), otherwise it's not detected.]

vt-alt avatar Jul 29 '22 15:07 vt-alt

Hi!

I have a branch where I'm experimenting with adding it (BTW, the flag was added to GCC in version 10).

The problem is that there are so many warnings, that it would crash all the time. So, I'll try fixing them one by one, and when we have a clean build, I'll add it to the default flags.

Cheers,

Alex

alejandro-colomar avatar Aug 02 '22 17:08 alejandro-colomar

(BTW, the flag was added to GCC in version 10).

Yes, but it's only stabilized and became more useful than experimental in gcc-12 so I would not recommend previous versions. Thanks!

vt-alt avatar Aug 02 '22 21:08 vt-alt