src: initialize some fields to suppress harmless valgrind errors
This commit is contained in:
@@ -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
@@ -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);
|
||||
|
||||
@@ -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 *);
|
||||
|
||||
Reference in New Issue
Block a user