src: initialize some fields to suppress harmless valgrind errors

This commit is contained in:
Markus F.X.J. Oberhumer
2024-04-24 12:36:22 +02:00
parent 6db0af8d04
commit c69b4561fb
16 changed files with 124 additions and 103 deletions
+3 -3
View File
@@ -180,7 +180,7 @@ typedef upx_int64_t upx_off_t;
#if defined(__clang__) || defined(__GNUC__)
#define noreturn noinline __attribute__((__noreturn__))
#elif (ACC_CC_MSC)
// do not use, generates annoying "warning C4702: unreachable code"
// do not use, triggers annoying "warning C4702: unreachable code"
////#define noreturn noinline __declspec(noreturn)
#define noreturn noinline
#else
@@ -458,7 +458,7 @@ noreturn void throwAssertFailed(const char *expr, const char *file, int line, co
#if defined(__clang__) || defined(__GNUC__)
#undef assert
#if DEBUG || 0
// generate a warning if assert() is used inside a "noexcept" context
// trigger a warning if assert() is used inside a "noexcept" context
#define assert(e) \
((void) (__acc_cte(e) || (assertFailed(#e, __FILE__, __LINE__, __func__), throw 1, 0)))
#else
@@ -707,7 +707,7 @@ struct upx_compress_config_t final {
}
};
#define NULL_cconf ((upx_compress_config_t *) nullptr)
#define NULL_cconf ((const upx_compress_config_t *) nullptr)
/*************************************************************************
// compression - result_t
+1 -2
View File
@@ -190,8 +190,7 @@ protected:
unsigned le_offset = 0;
unsigned exe_offset = 0;
le_header_t ih;
le_header_t oh;
le_header_t ih = {}, oh = {};
le_object_table_entry_t *iobject_table = nullptr;
le_object_table_entry_t *oobject_table = nullptr;
+1 -5
View File
@@ -1364,11 +1364,7 @@ int __acc_cdecl_main main(int argc, char *argv[]) /*noexcept*/ {
_set_abort_behavior(_WRITE_ABORT_MSG, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
#endif
acc_wildargv(&argc, &argv);
#if defined(__wasi__)
::srand((unsigned) time(nullptr));
#else
::srand((unsigned) clock());
#endif
upx_rand_init();
// info: main() is implicitly "noexcept", so we need a try block
#if 0
+1 -1
View File
@@ -86,7 +86,7 @@ protected:
LE32 firstreloc;
};
exe_header_t ih, oh;
exe_header_t ih = {}, oh = {};
unsigned ih_exesize = 0;
unsigned ih_imagesize = 0;
+1 -3
View File
@@ -75,9 +75,7 @@ static const CLANG_FORMAT_DUMMY_STATEMENT
**************************************************************************/
PackPs1::PackPs1(InputFile *f)
: super(f), isCon(!opt->ps1_exe.boot_only), is32Bit(!opt->ps1_exe.do_8bit), buildPart2(0),
foundBss(0), sa_cnt(0), overlap(0), sz_lunc(0), sz_lcpr(0), pad_code(0), bss_start(0),
bss_end(0) {
: super(f), isCon(!opt->ps1_exe.boot_only), is32Bit(!opt->ps1_exe.do_8bit) {
bele = &N_BELE_RTP::le_policy;
COMPILE_TIME_ASSERT(sizeof(ps1_exe_t) == 136)
+12 -12
View File
@@ -108,20 +108,20 @@ protected:
LE16 hi2, op3, lo2, op4;
};
ps1_exe_t ih, oh;
ps1_exe_hb_t bh;
ps1_exe_t ih = {}, oh = {};
ps1_exe_hb_t bh = {};
bool isCon;
bool is32Bit;
bool buildPart2;
bool foundBss;
unsigned ram_size;
unsigned sa_cnt, overlap;
unsigned sz_lunc, sz_lcpr;
unsigned pad_code;
unsigned bss_start, bss_end;
bool isCon = false;
bool is32Bit = false;
bool buildPart2 = false;
bool foundBss = false;
unsigned ram_size = 0;
unsigned sa_cnt = 0, overlap = 0;
unsigned sz_lunc = 0, sz_lcpr = 0;
unsigned pad_code = 0;
unsigned bss_start = 0, bss_end = 0;
// filesize-PS_HDR_SIZE
unsigned fdata_size;
unsigned fdata_size = 0;
};
/* vim:set ts=4 sw=4 et: */
+1 -1
View File
@@ -70,7 +70,7 @@ protected:
byte ___[12]; // esp,numfixups,flags
LE32 relocsize;
};
tmt_header_t ih, oh;
tmt_header_t ih = {}, oh = {};
};
/* vim:set ts=4 sw=4 et: */
+1 -1
View File
@@ -71,7 +71,7 @@ protected:
BE16 fh_reloc;
};
tos_header_t ih, oh;
tos_header_t ih = {}, oh = {};
// symbols for buildLoader()
struct LinkerSymbols {
+3 -26
View File
@@ -57,7 +57,7 @@ void Packer::assertPacker() const {
assert(getVersion() >= 11);
assert(getVersion() <= 14);
assert(strlen(getName()) <= 15);
// info: 36 is the limit for show_all_packers() in help.cpp, but 32 should be enough
// info: 36 is the limit for show_all_packers() in help.cpp, but 32 should be enough for now
assert(strlen(getFullName(nullptr)) <= 32);
assert(strlen(getFullName(opt)) <= 32);
assert(getCompressionMethods(M_ALL, 10) != nullptr);
@@ -471,30 +471,7 @@ unsigned Packer::getRandomId() const {
if (opt->debug.disable_random_id)
return 0x01020304;
unsigned id = 0;
#if 0 && defined(__unix__)
// Don't consume precious bytes from /dev/urandom.
int fd = open("/dev/urandom", O_RDONLY | O_BINARY);
if (fd < 0)
fd = open("/dev/random", O_RDONLY | O_BINARY);
if (fd >= 0) {
if (read(fd, &id, 4) != 4)
id = 0;
close(fd);
}
#endif
while (id == 0) {
#if (!(HAVE_GETTIMEOFDAY) || ((ACC_OS_DOS32) && defined(__DJGPP__))) && !defined(__wasi__)
id ^= (unsigned) time(nullptr);
id ^= ((unsigned) clock()) << 12;
#else
struct timeval tv;
gettimeofday(&tv, nullptr);
id ^= (unsigned) tv.tv_sec;
id ^= ((unsigned) tv.tv_usec) << 12; // shift into high-bits
#endif
#if HAVE_GETPID
id ^= (unsigned) getpid();
#endif
id ^= (unsigned) fi->st.st_ino;
id ^= (unsigned) fi->st.st_atime;
id ^= (unsigned) upx_rand();
@@ -950,9 +927,9 @@ int Packer::prepareMethods(int *methods, int ph_method, const int *all_methods)
// debug
if (opt->debug.use_random_method && nmethods >= 2) {
int method = methods[upx_rand() % nmethods];
NO_printf("\nuse_random_method = %#x (%d)\n", method, nmethods);
methods[0] = method;
nmethods = 1;
NO_printf("\nuse_random_method = %d\n", method);
}
return nmethods;
}
@@ -1019,10 +996,10 @@ done:
if (opt->debug.use_random_filter && nfilters >= 3 && filters[nfilters - 1] == 0) {
int filter_id = filters[upx_rand() % (nfilters - 1)];
if (filter_id > 0) {
NO_printf("\nuse_random_filter = %#x (%d)\n", filter_id, nfilters - 1);
filters[0] = filter_id;
filters[1] = 0;
nfilters = 2;
NO_printf("\nuse_random_filter = %d\n", filter_id);
}
}
return nfilters;
+2 -2
View File
@@ -579,7 +579,7 @@ protected:
ddirs_t ddirs[16];
};
pe_header_t ih, oh;
pe_header_t ih = {}, oh = {};
};
class PeFile64 : public PeFile {
@@ -640,7 +640,7 @@ protected:
ddirs_t ddirs[16];
};
pe_header_t ih, oh;
pe_header_t ih = {}, oh = {};
};
/* vim:set ts=4 sw=4 et: */
+1
View File
@@ -125,6 +125,7 @@ static_assert(sizeof(void *) == sizeof(long));
#include <type_traits>
#include <utility>
// C++ system headers
#include <algorithm>
#include <memory> // std::unique_ptr
// C++ multithreading (UPX currently does not use multithreading)
#if __STDC_NO_ATOMICS__
+18 -1
View File
@@ -26,7 +26,6 @@
*/
#include "system_headers.h"
#include <algorithm>
#define ACC_WANT_ACC_INCI_H 1
#include "miniacc.h"
#define ACC_WANT_ACCLIB_GETOPT 1
@@ -260,8 +259,26 @@ const char *upx_getenv(const char *envvar) noexcept {
return nullptr;
}
// random value from libc; quality is not important for UPX
int upx_rand(void) noexcept { return ::rand(); }
void upx_rand_init(void) noexcept {
unsigned seed = 0;
#if (!HAVE_GETTIMEOFDAY || (ACC_OS_DOS32 && defined(__DJGPP__))) && !defined(__wasi__)
seed ^= (unsigned) time(nullptr);
seed ^= ((unsigned) clock()) << 12;
#else
struct timeval tv = {};
(void) gettimeofday(&tv, nullptr);
seed ^= (unsigned) tv.tv_sec;
seed ^= ((unsigned) tv.tv_usec) << 12;
#endif
#if HAVE_GETPID
seed ^= ((unsigned) getpid()) << 4;
#endif
::srand(seed);
}
void *upx_calloc(size_t n, size_t element_size) may_throw {
size_t bytes = mem_size(element_size, n); // assert size
void *p = ::malloc(bytes);
+1
View File
@@ -149,6 +149,7 @@ noinline const char *upx_getenv(const char *envvar) noexcept;
void upx_memswap(void *a, void *b, size_t bytes) noexcept;
noinline void upx_rand_init(void) noexcept;
noinline int upx_rand(void) noexcept;
typedef int(__acc_cdecl_qsort *upx_compare_func_t)(const void *, const void *);