From b82a13c6ba48eb8711071342bec80798aca5de1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 21 Sep 2020 15:06:19 +0200 Subject: [PATCH] Add clang analyzer CI job --- .github/workflows/ci.yml | 20 ++++++++++++++++++++ AffinityPanel.c | 7 ++++--- htop.c | 2 ++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d6de8fe..5eb002cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,6 +55,26 @@ jobs: - name: Distcheck run: make distcheck DISTCHECK_CONFIGURE_FLAGS='--enable-werror --enable-openvz --enable-cgroup --enable-vserver --enable-ancient-vserver --enable-taskstats --enable-unicode --enable-hwloc --enable-setuid --enable-delayacct' + build-ubuntu-latest-clang-analyzer: + runs-on: ubuntu-latest + env: + CC: clang-11 + steps: + - uses: actions/checkout@v2 + - name: install clang repo + run: | + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key 2>/dev/null | sudo apt-key add - + sudo add-apt-repository 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main' -y + sudo apt-get update -q + - name: Install Dependencies + run: sudo apt-get install clang-11 clang-tools-11 libncursesw5-dev libhwloc-dev libnl-3-dev libnl-genl-3-dev + - name: Bootstrap + run: ./autogen.sh + - name: Configure + run: scan-build-11 -analyze-headers --status-bugs ./configure --enable-debug --enable-werror --enable-openvz --enable-cgroup --enable-vserver --enable-ancient-vserver --enable-taskstats --enable-unicode --enable-hwloc --enable-setuid --enable-delayacct + - name: Build + run: scan-build-11 -analyze-headers --status-bugs make -j"$(nproc)" + whitespace_check: runs-on: ubuntu-latest steps: diff --git a/AffinityPanel.c b/AffinityPanel.c index 1cae4ee4..79fe7f36 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -274,9 +274,10 @@ static MaskItem *AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, u } xSnprintf(&indent_buf[off], left, "%s", obj->next_sibling ? CRT_treeStr[TREE_STR_RTEE] : CRT_treeStr[TREE_STR_BEND]); - size_t len = strlen(&indent_buf[off]); - off += len; - left -= len; + // Uncomment when further appending to indent_buf + //size_t len = strlen(&indent_buf[off]); + //off += len; + //left -= len; } xSnprintf(buf, 64, "%s %s%u", type_name, index_prefix, index); diff --git a/htop.c b/htop.c index fbd6dee4..5054379d 100644 --- a/htop.c +++ b/htop.c @@ -107,6 +107,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) { printVersionFlag(); exit(0); case 's': + assert(optarg); /* please clang analyzer, cause optarg can be NULL in the 'u' case */ if (strcmp(optarg, "help") == 0) { for (int j = 1; j < Platform_numberOfFields; j++) { const char* name = Process_fields[j].name; @@ -158,6 +159,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) { flags.treeView = true; break; case 'p': { + assert(optarg); /* please clang analyzer, cause optarg can be NULL in the 'u' case */ char* argCopy = xStrdup(optarg); char* saveptr; char* pid = strtok_r(argCopy, ",", &saveptr);