paullouisageneau / libjuice

JUICE is a UDP Interactive Connectivity Establishment library
Mozilla Public License 2.0
410 stars 76 forks source link

Add option and initial config for clang-tidy #177

Closed VollmondT closed 1 year ago

VollmondT commented 1 year ago

I got interested in this case #176. I've also run another linter (clang-tidy). Here is the output:

libjuice/src/conn_poll.c:341:3: warning: Potential leak of memory pointed to by 'conn_impl' [clang-analyzer-unix.Malloc]
                JLOG_ERROR("UDP socket creation failed");
                ^
libjuice/src/log.h:33:25: note: expanded from macro 'JLOG_ERROR'
#define JLOG_ERROR(...) juice_log_write(JUICE_LOG_LEVEL_ERROR, __FILE__, __LINE__, __VA_ARGS__)
                        ^
libjuice/src/conn_poll.c:333:27: note: Memory is allocated
        conn_impl_t *conn_impl = calloc(1, sizeof(conn_impl_t));
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libjuice/src/conn_poll.c:334:6: note: Assuming 'conn_impl' is non-null
        if (!conn_impl) {
            ^~~~~~~~~~
libjuice/src/conn_poll.c:334:2: note: Taking false branch
        if (!conn_impl) {
        ^
libjuice/src/conn_poll.c:340:6: note: Assuming the condition is true
        if (conn_impl->sock == INVALID_SOCKET) {
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libjuice/src/conn_poll.c:340:2: note: Taking true branch
        if (conn_impl->sock == INVALID_SOCKET) {
        ^
libjuice/src/conn_poll.c:341:3: note: Potential leak of memory pointed to by 'conn_impl'
                JLOG_ERROR("UDP socket creation failed");
                ^
libjuice/src/log.h:33:25: note: expanded from macro 'JLOG_ERROR'
#define JLOG_ERROR(...) juice_log_write(JUICE_LOG_LEVEL_ERROR, __FILE__, __LINE__, __VA_ARGS__)

So, clang-tidy has been added to CMake. Here is more potential issues to investigate, but it is out of scope in given pull request.

VollmondT commented 1 year ago

I run on clang-tidy-14 but here is 10. Anyway 10 is good enough to caugh #176 https://github.com/paullouisageneau/libjuice/actions/runs/3087124920/jobs/4992167451#step:5:74 It make sense to use it.