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
+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 *);