all: update for clang-tidy-18

This commit is contained in:
Markus F.X.J. Oberhumer 2024-05-06 05:40:22 +02:00
parent 3e5ba5c064
commit 6fc0a00ac8
10 changed files with 89 additions and 72 deletions

View File

@ -7,9 +7,11 @@ Checks: >
bugprone-*, bugprone-*,
-bugprone-assignment-in-if-condition, -bugprone-assignment-in-if-condition,
-bugprone-branch-clone, -bugprone-branch-clone,
-bugprone-casting-through-void,
-bugprone-easily-swappable-parameters, -bugprone-easily-swappable-parameters,
-bugprone-empty-catch, -bugprone-empty-catch,
-bugprone-implicit-widening-of-multiplication-result, -bugprone-implicit-widening-of-multiplication-result,
-bugprone-inc-dec-in-conditions,
-bugprone-macro-parentheses, -bugprone-macro-parentheses,
-bugprone-narrowing-conversions, -bugprone-narrowing-conversions,
-bugprone-reserved-identifier, -bugprone-reserved-identifier,
@ -25,6 +27,7 @@ Checks: >
clang-diagnostic-*, clang-diagnostic-*,
performance-*, performance-*,
-performance-avoid-endl, -performance-avoid-endl,
-performance-enum-size,
-performance-unnecessary-value-param, -performance-unnecessary-value-param,
FormatStyle: file FormatStyle: file
HeaderFilterRegex: '.*' HeaderFilterRegex: '.*'

View File

@ -87,17 +87,19 @@ jobs:
if: ${{ matrix.use_extra }} if: ${{ matrix.use_extra }}
run: | run: |
sudo dpkg --add-architecture i386 sudo dpkg --add-architecture i386
sudo apt-get update sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install -y g++-multilib g++-mingw-w64-i686 g++-mingw-w64-x86-64 sudo apt-get install -y g++-multilib g++-mingw-w64-i686 g++-mingw-w64-x86-64
# make sure that we use posix-threads (pthread/winpthreads) and NOT win32-threads # make sure that we use posix-threads (pthread/winpthreads) and NOT win32-threads
for f in i686-w64-mingw32-g++ i686-w64-mingw32-gcc x86_64-w64-mingw32-g++ x86_64-w64-mingw32-gcc; do for f in i686-w64-mingw32-g++ i686-w64-mingw32-gcc x86_64-w64-mingw32-g++ x86_64-w64-mingw32-gcc; do
if test -f /usr/bin/$f-posix; then sudo update-alternatives --set $f /usr/bin/$f-posix; fi if test -f /usr/bin/$f-posix; then sudo update-alternatives --set $f /usr/bin/$f-posix; fi
ls -l /usr/bin/${f}*
done done
ls -l /etc/alternatives/*mingw* || true
sudo apt-get install -y libc6-dbg:i386 valgrind sudo apt-get install -y libc6-dbg:i386 valgrind
- name: Install Wine - name: Install Wine
if: ${{ matrix.use_extra && matrix.use_wine }} if: ${{ matrix.use_extra && matrix.use_wine }}
run: | run: |
sudo apt-get install -y wine wine32 wine64 sudo apt-get install -y wine wine32:i386 wine64
ls -l /usr/bin/wine* ls -l /usr/bin/wine*
mkdir -p -v ~/.wine && wineboot --init mkdir -p -v ~/.wine && wineboot --init
- uses: actions/checkout@v4 - uses: actions/checkout@v4

View File

@ -6,8 +6,10 @@ Checks: >
-*, -*,
bugprone-*, bugprone-*,
-bugprone-assignment-in-if-condition, -bugprone-assignment-in-if-condition,
-bugprone-casting-through-void,
-bugprone-easily-swappable-parameters, -bugprone-easily-swappable-parameters,
-bugprone-implicit-widening-of-multiplication-result, -bugprone-implicit-widening-of-multiplication-result,
-bugprone-inc-dec-in-conditions,
-bugprone-macro-parentheses, -bugprone-macro-parentheses,
-bugprone-reserved-identifier, -bugprone-reserved-identifier,
-bugprone-sizeof-expression, -bugprone-sizeof-expression,

View File

@ -8,6 +8,7 @@ Checks: >
-bugprone-assignment-in-if-condition, -bugprone-assignment-in-if-condition,
-bugprone-easily-swappable-parameters, -bugprone-easily-swappable-parameters,
-bugprone-implicit-widening-of-multiplication-result, -bugprone-implicit-widening-of-multiplication-result,
-bugprone-inc-dec-in-conditions,
-bugprone-macro-parentheses, -bugprone-macro-parentheses,
-bugprone-narrowing-conversions, -bugprone-narrowing-conversions,
-bugprone-reserved-identifier, -bugprone-reserved-identifier,

View File

@ -7,6 +7,7 @@ Checks: >
bugprone-*, bugprone-*,
-bugprone-assignment-in-if-condition, -bugprone-assignment-in-if-condition,
-bugprone-branch-clone, -bugprone-branch-clone,
-bugprone-casting-through-void,
-bugprone-easily-swappable-parameters, -bugprone-easily-swappable-parameters,
-bugprone-implicit-widening-of-multiplication-result, -bugprone-implicit-widening-of-multiplication-result,
-bugprone-macro-parentheses, -bugprone-macro-parentheses,

View File

@ -6,15 +6,30 @@
ifeq ($(UPX_MAKEFILE_EXTRA_MK_INCLUDED),) ifeq ($(UPX_MAKEFILE_EXTRA_MK_INCLUDED),)
override UPX_MAKEFILE_EXTRA_MK_INCLUDED := 1 override UPX_MAKEFILE_EXTRA_MK_INCLUDED := 1
#***********************************************************************
# support functions
#***********************************************************************
override check_defined = $(foreach 1,$1,$(if $(filter undefined,$(origin $1)),$(error ERROR: variable '$1' is not defined),)) override check_defined = $(foreach 1,$1,$(if $(filter undefined,$(origin $1)),$(error ERROR: variable '$1' is not defined),))
override check_undefined = $(foreach 1,$1,$(if $(filter undefined,$(origin $1)),,$(error ERROR: variable '$1' is already defined))) override check_undefined = $(foreach 1,$1,$(if $(filter undefined,$(origin $1)),,$(error ERROR: variable '$1' is already defined)))
$(call check_defined,run_config run_build)
$(call check_undefined,run_config_and_build) # return "1" or empty-string
override eq = $(if $(subst x$1,,x$2)$(subst x$2,,x$1),,1)
override ne = $(if $(subst x$1,,x$2)$(subst x$2,,x$1),1,)
override tolower = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1))))))))))))))))))))))))))
override toupper = $(subst a,A,$(subst b,B,$(subst c,C,$(subst d,D,$(subst e,E,$(subst f,F,$(subst g,G,$(subst h,H,$(subst i,I,$(subst j,J,$(subst k,K,$(subst l,L,$(subst m,M,$(subst n,N,$(subst o,O,$(subst p,P,$(subst q,Q,$(subst r,R,$(subst s,S,$(subst t,T,$(subst u,U,$(subst v,V,$(subst w,W,$(subst x,X,$(subst y,Y,$(subst z,Z,$1))))))))))))))))))))))))))
# canonicalize case of CMAKE_BUILD_TYPE to "Debug" and "Release"
override cm_build_type = $(if $(call eq,$1,),$(error EMPTY-build-type),$(if $(call eq,$(call tolower,$1),debug),Debug,$(if $(call eq,$(call tolower,$1),release),Release,$(if $(call eq,$(call tolower,$1),none),None,$1))))
#*********************************************************************** #***********************************************************************
# extra builds: some pre-defined build configurations # extra builds: some pre-defined build configurations
#*********************************************************************** #***********************************************************************
$(call check_defined,run_config run_build)
$(call check_undefined,run_config_and_build)
define run_config_and_build define run_config_and_build
$(call run_config,$1,$2) $(call run_config,$1,$2)
$(call run_build,$1,$2) $(call run_build,$1,$2)
@ -168,7 +183,7 @@ build/extra/cross-windows-mingw64/%: export CC = x86_64-w64-mingw32-gcc -static
build/extra/cross-windows-mingw64/%: export CXX = x86_64-w64-mingw32-g++ -static -D_WIN32_WINNT=0x0501 build/extra/cross-windows-mingw64/%: export CXX = x86_64-w64-mingw32-g++ -static -D_WIN32_WINNT=0x0501
build/extra/cross-windows-mingw64/%: CMAKE_SYSTEM_NAME ?= Windows build/extra/cross-windows-mingw64/%: CMAKE_SYSTEM_NAME ?= Windows
build/extra/cross-windows-mingw64/%: CMAKE_SYSTEM_PROCESSOR ?= AMD64 build/extra/cross-windows-mingw64/%: CMAKE_SYSTEM_PROCESSOR ?= AMD64
build/extra/cross-windows-mingw64/%: CMAKE_CROSSCOMPILING_EMULATOR ?= wine64 build/extra/cross-windows-mingw64/%: CMAKE_CROSSCOMPILING_EMULATOR ?= wine
# cross compiler: macOS arm64 (aarch64) # cross compiler: macOS arm64 (aarch64)
build/extra/cross-darwin-arm64/debug: PHONY; $(call run_config_and_build,$@,Debug) build/extra/cross-darwin-arm64/debug: PHONY; $(call run_config_and_build,$@,Debug)
@ -198,19 +213,20 @@ build/analyze/clang-analyzer/%: override CMAKE := $(SCAN_BUILD) $(CMAKE)
build/analyze/clang-analyzer/%: export CCC_CC ?= clang build/analyze/clang-analyzer/%: export CCC_CC ?= clang
build/analyze/clang-analyzer/%: export CCC_CXX ?= clang++ build/analyze/clang-analyzer/%: export CCC_CXX ?= clang++
# run clang-tidy: uses file compile_commands.json from an existing clang build # run clang-tidy: uses file compile_commands.json from an existing clang build;
# does not create any actual files, so purely PHONY # does not create any actual files, so purely PHONY
CLANG_TIDY_BUILD_BASE = build/extra/clang
RUN_CLANG_TIDY = time python3 ./misc/analyze/clang-tidy/run-clang-tidy.py -p $< RUN_CLANG_TIDY = time python3 ./misc/analyze/clang-tidy/run-clang-tidy.py -p $<
RUN_CLANG_TIDY_WERROR = $(RUN_CLANG_TIDY) '-warnings-as-errors=*' RUN_CLANG_TIDY_WERROR = $(RUN_CLANG_TIDY) '-warnings-as-errors=*'
build/analyze/clang-tidy-upx/debug build/analyze/clang-tidy-upx/release: build/extra/clang/$$(notdir $$@) PHONY build/analyze/clang-tidy-upx/debug build/analyze/clang-tidy-upx/release: $$(CLANG_TIDY_BUILD_BASE)/$$(notdir $$@) PHONY
$(RUN_CLANG_TIDY_WERROR) -config-file ./.clang-tidy '/src/.*\.cpp' $(RUN_CLANG_TIDY_WERROR) -config-file ./.clang-tidy '/src/.*\.cpp'
build/analyze/clang-tidy-bzip2/debug build/analyze/clang-tidy-bzip2/release: build/extra/clang/$$(notdir $$@) PHONY build/analyze/clang-tidy-bzip2/debug build/analyze/clang-tidy-bzip2/release: $$(CLANG_TIDY_BUILD_BASE)/$$(notdir $$@) PHONY
$(RUN_CLANG_TIDY) -config-file ./misc/analyze/clang-tidy/clang-tidy-bzip2.yml /vendor/bzip2/ $(RUN_CLANG_TIDY) -config-file ./misc/analyze/clang-tidy/clang-tidy-bzip2.yml /vendor/bzip2/
build/analyze/clang-tidy-ucl/debug build/analyze/clang-tidy-ucl/release: build/extra/clang/$$(notdir $$@) PHONY build/analyze/clang-tidy-ucl/debug build/analyze/clang-tidy-ucl/release: $$(CLANG_TIDY_BUILD_BASE)/$$(notdir $$@) PHONY
$(RUN_CLANG_TIDY_WERROR) -config-file ./misc/analyze/clang-tidy/clang-tidy-ucl.yml /vendor/ucl/ $(RUN_CLANG_TIDY_WERROR) -config-file ./misc/analyze/clang-tidy/clang-tidy-ucl.yml /vendor/ucl/
build/analyze/clang-tidy-zlib/debug build/analyze/clang-tidy-zlib/release: build/extra/clang/$$(notdir $$@) PHONY build/analyze/clang-tidy-zlib/debug build/analyze/clang-tidy-zlib/release: $$(CLANG_TIDY_BUILD_BASE)/$$(notdir $$@) PHONY
$(RUN_CLANG_TIDY_WERROR) -config-file ./misc/analyze/clang-tidy/clang-tidy-zlib.yml /vendor/zlib/ $(RUN_CLANG_TIDY_WERROR) -config-file ./misc/analyze/clang-tidy/clang-tidy-zlib.yml /vendor/zlib/
build/analyze/clang-tidy-zstd/debug build/analyze/clang-tidy-zstd/release: build/extra/clang/$$(notdir $$@) PHONY build/analyze/clang-tidy-zstd/debug build/analyze/clang-tidy-zstd/release: $$(CLANG_TIDY_BUILD_BASE)/$$(notdir $$@) PHONY
$(RUN_CLANG_TIDY) -config-file ./misc/analyze/clang-tidy/clang-tidy-zstd.yml /vendor/zstd/ $(RUN_CLANG_TIDY) -config-file ./misc/analyze/clang-tidy/clang-tidy-zstd.yml /vendor/zstd/
build/analyze/clang-tidy/debug build/analyze/clang-tidy/release: build/analyze/clang-tidy-upx/$$(notdir $$@) build/analyze/clang-tidy/debug build/analyze/clang-tidy/release: build/analyze/clang-tidy-upx/$$(notdir $$@)
build/analyze/clang-tidy/debug build/analyze/clang-tidy/release: build/analyze/clang-tidy-bzip2/$$(notdir $$@) build/analyze/clang-tidy/debug build/analyze/clang-tidy/release: build/analyze/clang-tidy-bzip2/$$(notdir $$@)

View File

@ -40,16 +40,18 @@ static bool update_capacity(unsigned size, unsigned *capacity) {
return true; return true;
} }
static void internal_error(const char *format, ...) attribute_format(1, 2); template <class T>
static void internal_error(const char *format, ...) { static noinline T **realloc_array(T **array, size_t capacity) {
static char buf[1024]; // NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
va_list ap; void *p = realloc(array, mem_size(sizeof(T *), capacity));
return static_cast<T **>(p);
}
va_start(ap, format); template <class T>
upx_safe_vsnprintf(buf, sizeof(buf), format, ap); static noinline void free_array(T **array, size_t count) {
va_end(ap); for (size_t i = 0; i < count; i++)
delete array[i];
throwInternalError(buf); ::free(array); // NOLINT(bugprone-multi-level-implicit-pointer-conversion)
} }
/************************************************************************* /*************************************************************************
@ -106,17 +108,9 @@ ElfLinker::ElfLinker(const N_BELE_RTP::AbstractPolicy *b) noexcept : bele(b) {}
ElfLinker::~ElfLinker() noexcept { ElfLinker::~ElfLinker() noexcept {
delete[] input; delete[] input;
delete[] output; delete[] output;
free_array(sections, nsections);
unsigned ic; free_array(symbols, nsymbols);
for (ic = 0; ic < nsections; ic++) free_array(relocations, nrelocations);
delete sections[ic];
::free(sections);
for (ic = 0; ic < nsymbols; ic++)
delete symbols[ic];
::free(symbols);
for (ic = 0; ic < nrelocations; ic++)
delete relocations[ic];
::free(relocations);
} }
void ElfLinker::init(const void *pdata_v, int plen, unsigned pxtra) { void ElfLinker::init(const void *pdata_v, int plen, unsigned pxtra) {
@ -302,7 +296,7 @@ ElfLinker::Section *ElfLinker::findSection(const char *name, bool fatal) const {
if (strcmp(sections[ic]->name, name) == 0) if (strcmp(sections[ic]->name, name) == 0)
return sections[ic]; return sections[ic];
if (fatal) if (fatal)
internal_error("unknown section %s\n", name); throwInternalError("unknown section %s\n", name);
return nullptr; return nullptr;
} }
@ -311,7 +305,7 @@ ElfLinker::Symbol *ElfLinker::findSymbol(const char *name, bool fatal) const {
if (strcmp(symbols[ic]->name, name) == 0) if (strcmp(symbols[ic]->name, name) == 0)
return symbols[ic]; return symbols[ic];
if (fatal) if (fatal)
internal_error("unknown symbol %s\n", name); throwInternalError("unknown symbol %s\n", name);
return nullptr; return nullptr;
} }
@ -321,8 +315,7 @@ ElfLinker::Section *ElfLinker::addSection(const char *sname, const void *sdata,
if (!sdata && (!strcmp("ABS*", sname) || !strcmp("UND*", sname))) if (!sdata && (!strcmp("ABS*", sname) || !strcmp("UND*", sname)))
return nullptr; return nullptr;
if (update_capacity(nsections, &nsections_capacity)) if (update_capacity(nsections, &nsections_capacity))
sections = sections = realloc_array(sections, nsections_capacity);
static_cast<Section **>(realloc(sections, nsections_capacity * sizeof(Section *)));
assert(sections); assert(sections);
assert(sname); assert(sname);
assert(sname[0]); assert(sname[0]);
@ -338,7 +331,7 @@ ElfLinker::Symbol *ElfLinker::addSymbol(const char *name, const char *section,
upx_uint64_t offset) { upx_uint64_t offset) {
NO_printf("addSymbol: %s %s 0x%llx\n", name, section, offset); NO_printf("addSymbol: %s %s 0x%llx\n", name, section, offset);
if (update_capacity(nsymbols, &nsymbols_capacity)) if (update_capacity(nsymbols, &nsymbols_capacity))
symbols = static_cast<Symbol **>(realloc(symbols, nsymbols_capacity * sizeof(Symbol *))); symbols = realloc_array(symbols, nsymbols_capacity);
assert(symbols != nullptr); assert(symbols != nullptr);
assert(name); assert(name);
assert(name[0]); assert(name[0]);
@ -352,8 +345,7 @@ ElfLinker::Symbol *ElfLinker::addSymbol(const char *name, const char *section,
ElfLinker::Relocation *ElfLinker::addRelocation(const char *section, unsigned off, const char *type, ElfLinker::Relocation *ElfLinker::addRelocation(const char *section, unsigned off, const char *type,
const char *symbol, upx_uint64_t add) { const char *symbol, upx_uint64_t add) {
if (update_capacity(nrelocations, &nrelocations_capacity)) if (update_capacity(nrelocations, &nrelocations_capacity))
relocations = static_cast<Relocation **>( relocations = realloc_array(relocations, nrelocations_capacity);
realloc(relocations, (nrelocations_capacity) * sizeof(Relocation *)));
assert(relocations != nullptr); assert(relocations != nullptr);
Relocation *rel = new Relocation(findSection(section), off, type, findSymbol(symbol), add); Relocation *rel = new Relocation(findSection(section), off, type, findSymbol(symbol), add);
relocations[nrelocations++] = rel; relocations[nrelocations++] = rel;
@ -361,8 +353,7 @@ ElfLinker::Relocation *ElfLinker::addRelocation(const char *section, unsigned of
} }
#if 0 #if 0
void ElfLinker::setLoaderAlignOffset(int phase) void ElfLinker::setLoaderAlignOffset(int phase) {
{
// assert(phase & 0); // assert(phase & 0);
NO_printf("\nFIXME: ElfLinker::setLoaderAlignOffset %d\n", phase); NO_printf("\nFIXME: ElfLinker::setLoaderAlignOffset %d\n", phase);
} }
@ -474,10 +465,10 @@ void ElfLinker::relocate() {
value = rel->value->offset; value = rel->value->offset;
} else if (strcmp(rel->value->section->name, "*UND*") == 0 && } else if (strcmp(rel->value->section->name, "*UND*") == 0 &&
rel->value->offset == 0xdeaddead) rel->value->offset == 0xdeaddead)
internal_error("undefined symbol '%s' referenced\n", rel->value->name); throwInternalError("undefined symbol '%s' referenced\n", rel->value->name);
else if (rel->value->section->output == nullptr) else if (rel->value->section->output == nullptr)
internal_error("can not apply reloc '%s:%x' without section '%s'\n", rel->section->name, throwInternalError("can not apply reloc '%s:%x' without section '%s'\n",
rel->offset, rel->value->section->name); rel->section->name, rel->offset, rel->value->section->name);
else { else {
value = rel->value->section->offset + rel->value->offset + rel->add; value = rel->value->section->offset + rel->value->offset + rel->add;
} }
@ -495,7 +486,7 @@ void ElfLinker::relocate() {
void ElfLinker::defineSymbol(const char *name, upx_uint64_t value) { void ElfLinker::defineSymbol(const char *name, upx_uint64_t value) {
Symbol *symbol = findSymbol(name); Symbol *symbol = findSymbol(name);
if (strcmp(symbol->section->name, "*ABS*") == 0) if (strcmp(symbol->section->name, "*ABS*") == 0)
internal_error("defineSymbol: symbol '%s' is *ABS*\n", name); throwInternalError("defineSymbol: symbol '%s' is *ABS*\n", name);
else if (strcmp(symbol->section->name, "*UND*") == 0) // for undefined symbols else if (strcmp(symbol->section->name, "*UND*") == 0) // for undefined symbols
symbol->offset = value; symbol->offset = value;
else if (strcmp(symbol->section->name, name) == 0) // for sections else if (strcmp(symbol->section->name, name) == 0) // for sections
@ -506,7 +497,7 @@ void ElfLinker::defineSymbol(const char *name, upx_uint64_t value) {
value += section->size; value += section->size;
} }
} else } else
internal_error("defineSymbol: symbol '%s' already defined\n", name); throwInternalError("defineSymbol: symbol '%s' already defined\n", name);
} }
// debugging support // debugging support
@ -553,7 +544,7 @@ void ElfLinker::alignWithByte(unsigned len, byte b) {
} }
void ElfLinker::relocate1(const Relocation *rel, byte *, upx_uint64_t, const char *) { void ElfLinker::relocate1(const Relocation *rel, byte *, upx_uint64_t, const char *) {
internal_error("unknown relocation type '%s\n'", rel->type); throwInternalError("unknown relocation type '%s\n'", rel->type);
} }
/************************************************************************* /*************************************************************************
@ -563,14 +554,13 @@ void ElfLinker::relocate1(const Relocation *rel, byte *, upx_uint64_t, const cha
**************************************************************************/ **************************************************************************/
#if 0 // FIXME #if 0 // FIXME
static void check8(const Relocation *rel, const byte *location, int v, int d) static void check8(const Relocation *rel, const byte *location, int v, int d) {
{
if (v < -128 || v > 127) if (v < -128 || v > 127)
internal_error("value out of range (%d) in reloc %s:%x\n", throwInternalError("value out of range (%d) in reloc %s:%x\n", v, rel->section->name,
v, rel->section->name, rel->offset); rel->offset);
if (d < -128 || d > 127) if (d < -128 || d > 127)
internal_error("displacement target out of range (%d) in reloc %s:%x\n", throwInternalError("displacement target out of range (%d) in reloc %s:%x\n", v,
v, rel->section->name, rel->offset); rel->section->name, rel->offset);
} }
#endif #endif
@ -594,8 +584,8 @@ void ElfLinkerAMD64::relocate1(const Relocation *rel, byte *location, upx_uint64
if (strcmp(type, "8") == 0) { if (strcmp(type, "8") == 0) {
int displ = (upx_int8_t) *location + (int) value; int displ = (upx_int8_t) *location + (int) value;
if (range_check && (displ < -128 || displ > 127)) if (range_check && (displ < -128 || displ > 127))
internal_error("target out of range (%d) in reloc %s:%x\n", displ, rel->section->name, throwInternalError("target out of range (%d) in reloc %s:%x\n", displ,
rel->offset); rel->section->name, rel->offset);
*location += value; *location += value;
} else if (strcmp(type, "16") == 0) } else if (strcmp(type, "16") == 0)
set_le16(location, get_le16(location) + value); set_le16(location, get_le16(location) + value);
@ -800,12 +790,12 @@ void ElfLinkerPpc32::relocate1(const Relocation *rel, byte *location, upx_uint64
// Note that original (*location).displ is ignored. // Note that original (*location).displ is ignored.
if (strcmp(type, "24") == 0) { if (strcmp(type, "24") == 0) {
if (3 & value) if (3 & value)
internal_error("unaligned word displacement"); throwInternalError("unaligned word displacement");
// FIXME: displacement overflow? // FIXME: displacement overflow?
set_be32(location, (0xfc000003 & get_be32(location)) + (0x03fffffc & value)); set_be32(location, (0xfc000003 & get_be32(location)) + (0x03fffffc & value));
} else if (strcmp(type, "14") == 0) { } else if (strcmp(type, "14") == 0) {
if (3 & value) if (3 & value)
internal_error("unaligned word displacement"); throwInternalError("unaligned word displacement");
// FIXME: displacement overflow? // FIXME: displacement overflow?
set_be32(location, (0xffff0003 & get_be32(location)) + (0x0000fffc & value)); set_be32(location, (0xffff0003 & get_be32(location)) + (0x0000fffc & value));
} else } else
@ -837,19 +827,19 @@ void ElfLinkerPpc64le::relocate1(const Relocation *rel, byte *location, upx_uint
if (strncmp(type, "14", 2) == 0) { // for "14" and "14S" if (strncmp(type, "14", 2) == 0) { // for "14" and "14S"
if (3 & value) if (3 & value)
internal_error("unaligned word displacement"); throwInternalError("unaligned word displacement");
// FIXME: displacement overflow? // FIXME: displacement overflow?
set_le32(location, (0xffff0003 & get_le32(location)) + (0x0000fffc & value)); set_le32(location, (0xffff0003 & get_le32(location)) + (0x0000fffc & value));
} else if (strncmp(type, "24", 2) == 0) { // for "24" and "24S" } else if (strncmp(type, "24", 2) == 0) { // for "24" and "24S"
if (3 & value) if (3 & value)
internal_error("unaligned word displacement"); throwInternalError("unaligned word displacement");
// FIXME: displacement overflow? // FIXME: displacement overflow?
set_le32(location, (0xfc000003 & get_le32(location)) + (0x03fffffc & value)); set_le32(location, (0xfc000003 & get_le32(location)) + (0x03fffffc & value));
} else if (strcmp(type, "8") == 0) { } else if (strcmp(type, "8") == 0) {
int displ = (upx_int8_t) *location + (int) value; int displ = (upx_int8_t) *location + (int) value;
if (range_check && (displ < -128 || displ > 127)) if (range_check && (displ < -128 || displ > 127))
internal_error("target out of range (%d) in reloc %s:%x\n", displ, rel->section->name, throwInternalError("target out of range (%d) in reloc %s:%x\n", displ,
rel->offset); rel->section->name, rel->offset);
*location += value; *location += value;
} else if (strcmp(type, "16") == 0) } else if (strcmp(type, "16") == 0)
set_le16(location, get_le16(location) + value); set_le16(location, get_le16(location) + value);
@ -887,19 +877,19 @@ void ElfLinkerPpc64::relocate1(const Relocation *rel, byte *location, upx_uint64
if (strncmp(type, "14", 2) == 0) { // for "14" and "14S" if (strncmp(type, "14", 2) == 0) { // for "14" and "14S"
if (3 & value) if (3 & value)
internal_error("unaligned word displacement"); throwInternalError("unaligned word displacement");
// FIXME: displacement overflow? // FIXME: displacement overflow?
set_be32(location, (0xffff0003 & get_be32(location)) + (0x0000fffc & value)); set_be32(location, (0xffff0003 & get_be32(location)) + (0x0000fffc & value));
} else if (strncmp(type, "24", 2) == 0) { // for "24" and "24S" } else if (strncmp(type, "24", 2) == 0) { // for "24" and "24S"
if (3 & value) if (3 & value)
internal_error("unaligned word displacement"); throwInternalError("unaligned word displacement");
// FIXME: displacement overflow? // FIXME: displacement overflow?
set_be32(location, (0xfc000003 & get_be32(location)) + (0x03fffffc & value)); set_be32(location, (0xfc000003 & get_be32(location)) + (0x03fffffc & value));
} else if (strcmp(type, "8") == 0) { } else if (strcmp(type, "8") == 0) {
int displ = (upx_int8_t) *location + (int) value; int displ = (upx_int8_t) *location + (int) value;
if (range_check && (displ < -128 || displ > 127)) if (range_check && (displ < -128 || displ > 127))
internal_error("target out of range (%d) in reloc %s:%x\n", displ, rel->section->name, throwInternalError("target out of range (%d) in reloc %s:%x\n", displ,
rel->offset); rel->section->name, rel->offset);
*location += value; *location += value;
} else if (strcmp(type, "16") == 0) } else if (strcmp(type, "16") == 0)
set_be16(location, get_be16(location) + value); set_be16(location, get_be16(location) + value);
@ -927,8 +917,8 @@ void ElfLinkerX86::relocate1(const Relocation *rel, byte *location, upx_uint64_t
if (strcmp(type, "8") == 0) { if (strcmp(type, "8") == 0) {
int displ = (upx_int8_t) *location + (int) value; int displ = (upx_int8_t) *location + (int) value;
if (range_check && (displ < -128 || displ > 127)) if (range_check && (displ < -128 || displ > 127))
internal_error("target out of range (%d,%d,%llu) in reloc %s:%x\n", displ, *location, throwInternalError("target out of range (%d,%d,%llu) in reloc %s:%x\n", displ,
value, rel->section->name, rel->offset); *location, value, rel->section->name, rel->offset);
*location += value; *location += value;
} else if (strcmp(type, "16") == 0) } else if (strcmp(type, "16") == 0)
set_le16(location, get_le16(location) + value); set_le16(location, get_le16(location) + value);

View File

@ -1116,7 +1116,7 @@ void main_get_envoptions() {
if (targc > 1) if (targc > 1)
targv = (const char **) upx_calloc(targc + 1, sizeof(char *)); targv = (const char **) upx_calloc(targc + 1, sizeof(char *));
if (targv == nullptr) { if (targv == nullptr) {
free(env); ::free(env);
return; return;
} }
@ -1155,8 +1155,8 @@ void main_get_envoptions() {
e_envopt(targv[mfx_optind]); e_envopt(targv[mfx_optind]);
/* clean up */ /* clean up */
free(targv); ::free(targv); // NOLINT(bugprone-multi-level-implicit-pointer-conversion)
free(env); ::free(env);
#endif /* defined(OPTIONS_VAR) */ #endif /* defined(OPTIONS_VAR) */
} }

View File

@ -859,6 +859,7 @@ public:
outputlen = 0; outputlen = 0;
// sort the sections by name before adding them all // sort the sections by name before adding them all
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
upx_qsort(sections, nsections, sizeof(Section *), ImportLinker::compare); upx_qsort(sections, nsections, sizeof(Section *), ImportLinker::compare);
for (unsigned ic = 0; ic < nsections; ic++) for (unsigned ic = 0; ic < nsections; ic++)
@ -1041,6 +1042,7 @@ unsigned PeFile::processImports0(ord_mask_t ord_mask) // pass 1
mb_oimport.clear(); mb_oimport.clear();
oimport = mb_oimport; oimport = mb_oimport;
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
upx_qsort(idlls, dllnum, sizeof(*idlls), UDll::compare); upx_qsort(idlls, dllnum, sizeof(*idlls), UDll::compare);
info("Processing imports: %d DLLs", dllnum); info("Processing imports: %d DLLs", dllnum);

View File

@ -77,7 +77,7 @@ T *NewArray(upx_uint64_t n) may_throw {
T *array = new T[size_t(n)]; T *array = new T[size_t(n)];
#if !defined(__SANITIZE_MEMORY__) #if !defined(__SANITIZE_MEMORY__)
if (array != nullptr && bytes > 0) { if (array != nullptr && bytes > 0) {
memset(array, 0xfb, bytes); memset(array, 0xfb, bytes); // NOLINT(bugprone-multi-level-implicit-pointer-conversion)
(void) VALGRIND_MAKE_MEM_UNDEFINED(array, bytes); (void) VALGRIND_MAKE_MEM_UNDEFINED(array, bytes);
} }
#endif #endif