From 5edfda46e5b24c3337762f33e01a94dce08450e3 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Sat, 8 Jul 2023 09:59:41 +0200 Subject: [PATCH] all: clang-tidy updates --- .clang-tidy | 2 +- ...yml => static-analyzer-clang-analyzer.yml} | 7 +++-- .../workflows/static-analyzer-clang-tidy.yml | 31 +++++++++++++++++++ src/help.cpp | 13 ++++---- src/p_lx_elf.cpp | 6 +++- src/p_lx_elf.h | 2 +- src/ui.cpp | 3 +- src/ui.h | 2 +- src/work.cpp | 1 - 9 files changed, 52 insertions(+), 15 deletions(-) rename .github/workflows/{static-analyzer-clang.yml => static-analyzer-clang-analyzer.yml} (78%) create mode 100644 .github/workflows/static-analyzer-clang-tidy.yml diff --git a/.clang-tidy b/.clang-tidy index 4568c501..59a3cdba 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,6 +1,6 @@ # for clang-tidy-16 from https://clang.llvm.org/extra/clang-tidy/ --- -Checks: 'bugprone-exception-*,clang-analyzer-*,-clang-analyzer-optin.performance.Padding,-clang-analyzer-security.insecureAPI.strcpy,clang-diagnostics-*' +Checks: 'bugprone-exception-*,clang-analyzer-*,-clang-analyzer-optin.performance.Padding,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,-clang-analyzer-security.insecureAPI.strcpy,clang-diagnostics-*' FormatStyle: file HeaderFilterRegex: '.*' ... diff --git a/.github/workflows/static-analyzer-clang.yml b/.github/workflows/static-analyzer-clang-analyzer.yml similarity index 78% rename from .github/workflows/static-analyzer-clang.yml rename to .github/workflows/static-analyzer-clang-analyzer.yml index 1ffee67e..8e5de988 100644 --- a/.github/workflows/static-analyzer-clang.yml +++ b/.github/workflows/static-analyzer-clang-analyzer.yml @@ -1,12 +1,12 @@ # Copyright (C) Markus Franz Xaver Johannes Oberhumer -name: 'Static Analyzer - clang scan-build' +name: 'Static Analyzer - clang-analyzer' on: schedule: [cron: '20 5 * * 3'] # run weekly Wednesday 05:20 UTC workflow_dispatch: jobs: - job-analyze-clang: # uses cmake + make + job-analyze-clang-analyzer: # uses cmake + make strategy: fail-fast: false matrix: {container: ['alpine:3.16','alpine:3.17','alpine:3.18','alpine:edge','i386/alpine:edge']} @@ -15,7 +15,7 @@ jobs: container: ${{ matrix.container }} steps: - name: ${{ format('Install packages {0}', matrix.container) }} - run: 'apk update && apk upgrade && apk add bash clang clang-analyzer cmake g++ git make' + run: 'apk update && apk upgrade && apk add clang clang-analyzer cmake g++ git make' - name: ${{ format('Check out UPX {0} source code', github.ref_name) }} run: | git clone --branch "$GITHUB_REF_NAME" --depth 1 https://github.com/upx/upx @@ -23,4 +23,5 @@ jobs: - name: 'Perform clang scan-build Analysis Debug' run: 'make -C upx build/extra/scan-build/debug' - name: 'Perform clang scan-build Analysis Release' + if: success() || failure() # run this step even if the previous step failed run: 'make -C upx build/extra/scan-build/release' diff --git a/.github/workflows/static-analyzer-clang-tidy.yml b/.github/workflows/static-analyzer-clang-tidy.yml new file mode 100644 index 00000000..de0d4e00 --- /dev/null +++ b/.github/workflows/static-analyzer-clang-tidy.yml @@ -0,0 +1,31 @@ +# Copyright (C) Markus Franz Xaver Johannes Oberhumer +name: 'Static Analyzer - clang-tidy' + +on: + schedule: [cron: '30 5 * * 3'] # run weekly Wednesday 05:30 UTC + workflow_dispatch: + +jobs: + job-analyze-clang-tidy: # uses cmake + make + strategy: + fail-fast: false + matrix: {container: ['alpine:edge','i386/alpine:edge']} + name: ${{ format('Analyze clang-tidy {0}', matrix.container) }} + runs-on: ubuntu-latest + container: ${{ matrix.container }} + steps: + - name: ${{ format('Install packages {0}', matrix.container) }} + run: 'apk update && apk upgrade && apk add clang clang-extra-tools cmake g++ git make' + - name: ${{ format('Check out UPX {0} source code', github.ref_name) }} + run: | + git clone --branch "$GITHUB_REF_NAME" --depth 1 https://github.com/upx/upx + git -C upx submodule update --init + - name: 'Perform clang-tidy Analysis Debug' + run: | + make -C upx build/extra/clang/debug + run-clang-tidy -p upx/build/extra/clang/debug + - name: 'Perform clang-tidy Analysis Release' + if: success() || failure() # run this step even if the previous step failed + run: | + make -C upx build/extra/clang/release + run-clang-tidy -p upx/build/extra/clang/release diff --git a/src/help.cpp b/src/help.cpp index 7aa85c42..2424d4ac 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -26,9 +26,10 @@ */ #include "conf.h" -#include "packmast.h" -#include "packer.h" #include "compress/compress.h" // upx_ucl_version_string() +// for list_all_packers(): +#include "packer.h" +#include "packmast.h" // PackMaster::visitAllPackers /************************************************************************* // header @@ -89,7 +90,7 @@ void show_usage(void) { } /************************************************************************* -// util +// list_all_packers() **************************************************************************/ namespace { @@ -121,8 +122,9 @@ struct PackerNames { return strcmp(((const Entry *) a)->sname, ((const Entry *) b)->sname); } }; +} // namespace -static void show_all_packers(FILE *f, int verbose) { +static void list_all_packers(FILE *f, int verbose) { Options o; o.reset(); PackerNames pn; @@ -152,7 +154,6 @@ static void show_all_packers(FILE *f, int verbose) { if (verbose <= 0 && pn.names_count) con_fprintf(f, "\n"); } -} // namespace /************************************************************************* // help @@ -291,7 +292,7 @@ void show_help(int verbose) { fg = con_fg(f, FG_YELLOW); con_fprintf(f, "\nThis version supports:\n"); fg = con_fg(f, fg); - show_all_packers(f, verbose); + list_all_packers(f, verbose); } else { con_fprintf(f, "\nType '%s --help' for more detailed help.\n", progname); } diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index 1a5636ec..8cdca2c3 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -60,12 +60,14 @@ static constexpr unsigned MAX_ELF_HDR_64 = 1024; static unsigned const EF_ARM_EABI_VER4 = 0x04000000; static unsigned const EF_ARM_EABI_VER5 = 0x05000000; -unsigned char PackLinuxElf::o_shstrtab[] = { \ +/*static*/ const unsigned char PackLinuxElf::o_shstrtab[] = { \ /*start*/ '\0', /*offset 1*/ '.','n','o','t','e','.','g','n','u','.','b','u','i','l','d','-','i','d','\0', /*offset 20*/ '.','s','h','s','t','r','t','a','b','\0' }; +// NOLINTBEGIN(clang-analyzer-*) + static unsigned umin(unsigned a, unsigned b) { @@ -8487,4 +8489,6 @@ void PackLinuxElf::unpack(OutputFile * /*fo*/) throwCantUnpack("internal error"); } +// NOLINTEND(clang-analyzer-*) + /* vim:set ts=4 sw=4 et: */ diff --git a/src/p_lx_elf.h b/src/p_lx_elf.h index dbfafdb1..48ca4046 100644 --- a/src/p_lx_elf.h +++ b/src/p_lx_elf.h @@ -127,7 +127,7 @@ protected: MemBuffer note_body; // concatenated contents of PT_NOTEs, if any unsigned note_size; // total size of PT_NOTEs int o_elf_shnum; // num output Shdrs - static unsigned char o_shstrtab[]; + static const unsigned char o_shstrtab[]; }; class PackLinuxElf32 : public PackLinuxElf diff --git a/src/ui.cpp b/src/ui.cpp index 82ac4939..bb66c43f 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -79,6 +79,7 @@ struct UiPacker::State { #endif }; +// static unsigned UiPacker::total_files = 0; unsigned UiPacker::total_files_done = 0; upx_uint64_t UiPacker::total_c_len = 0; @@ -155,7 +156,7 @@ static const char *mkline(upx_uint64_t fu_len, upx_uint64_t fc_len, upx_uint64_t // **************************************************************************/ -UiPacker::UiPacker(const Packer *p_) : ui_pass(0), ui_total_passes(0), p(p_), s(nullptr) { +UiPacker::UiPacker(const Packer *p_) : p(p_) { static upx_std_once_flag init_done; upx_std_call_once(init_done, init_global_constants); diff --git a/src/ui.h b/src/ui.h index cff70a5e..12ebbc83 100644 --- a/src/ui.h +++ b/src/ui.h @@ -84,7 +84,7 @@ public: protected: virtual void printInfo(int nl = 0); - const Packer *p = nullptr; + const Packer *const p; // callback upx_callback_t cb = {}; diff --git a/src/work.cpp b/src/work.cpp index 25871900..8d26db9f 100644 --- a/src/work.cpp +++ b/src/work.cpp @@ -33,7 +33,6 @@ #include "conf.h" #include "file.h" #include "packmast.h" -#include "packer.h" #include "ui.h" #if (ACC_OS_DOS32) && defined(__DJGPP__)