From d7754a97c7d003eb76bf09802a3ca84d8b24ca28 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Fri, 7 Jul 2023 21:40:36 +0200 Subject: [PATCH] all: add support for clang-tidy --- .clang-tidy | 6 ++++++ src/check/dt_impl.cpp | 2 ++ src/compress/compress_lzma.cpp | 3 +++ src/compress/compress_zlib.cpp | 2 ++ src/pefile.h | 18 +++++++++--------- 5 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 00000000..4568c501 --- /dev/null +++ b/.clang-tidy @@ -0,0 +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-*' +FormatStyle: file +HeaderFilterRegex: '.*' +... diff --git a/src/check/dt_impl.cpp b/src/check/dt_impl.cpp index 477729ba..34ea5430 100644 --- a/src/check/dt_impl.cpp +++ b/src/check/dt_impl.cpp @@ -52,7 +52,9 @@ #pragma clang diagnostic ignored "-Wtautological-constant-compare" #endif +// NOLINTBEGIN(bugprone-exception-escape) #include +// NOLINTEND(bugprone-exception-escape) #endif // DOCTEST_CONFIG_DISABLE diff --git a/src/compress/compress_lzma.cpp b/src/compress/compress_lzma.cpp index 791c4586..c6d4c198 100644 --- a/src/compress/compress_lzma.cpp +++ b/src/compress/compress_lzma.cpp @@ -207,9 +207,12 @@ error: **************************************************************************/ // ensure proper nullptr usage +// TODO later: examine why we need this in the first place #include #undef NULL +// NOLINTBEGIN(clang-analyzer-optin.cplusplus.*) #define NULL nullptr +// NOLINTEND(clang-analyzer-optin.cplusplus.*) #if defined(__GNUC__) #undef __null #define __null nullptr diff --git a/src/compress/compress_zlib.cpp b/src/compress/compress_zlib.cpp index d90bc2ea..72d85f0b 100644 --- a/src/compress/compress_zlib.cpp +++ b/src/compress/compress_zlib.cpp @@ -27,8 +27,10 @@ #include "../conf.h" #include "compress.h" #include "../util/membuffer.h" +// NOLINTBEGIN(clang-analyzer-optin.performance.Padding) #include #include +// NOLINTEND(clang-analyzer-optin.performance.Padding) void zlib_compress_config_t::reset() noexcept { mem_clear(this); diff --git a/src/pefile.h b/src/pefile.h index b858dd1d..9cdccdda 100644 --- a/src/pefile.h +++ b/src/pefile.h @@ -417,16 +417,16 @@ protected: struct upx_rleaf; MemBuffer mb_start; - const byte *start; - byte *newstart; - upx_rnode *root; - upx_rleaf *head; - upx_rleaf *current; - unsigned dsize; - unsigned ssize; + const byte *start = nullptr; + byte *newstart = nullptr; + upx_rnode *root = nullptr; + upx_rleaf *head = nullptr; + upx_rleaf *current = nullptr; + unsigned dsize = 0; + unsigned ssize = 0; - const byte *ibufstart; - const byte *ibufend; + const byte *ibufstart = nullptr; + const byte *ibufend = nullptr; void check(const res_dir *, unsigned); upx_rnode *convert(const void *, upx_rnode *, unsigned);