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 -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;