Cosmetic cleanups.

This commit is contained in:
Markus F.X.J. Oberhumer
2016-10-06 12:31:03 +02:00
parent 022ba32c1a
commit b3a8d02caf
4 changed files with 23 additions and 19 deletions
+1 -1
View File
@@ -472,7 +472,7 @@ struct upx_callback_t
template <class T, T default_value, T min_value, T max_value>
struct OptVar
{
typedef T Type;
typedef T value_type;
static const T default_value_c = default_value;
static const T min_value_c = min_value;
static const T max_value_c = max_value;
+2 -2
View File
@@ -170,7 +170,7 @@ void FileBase::write(const void *buf, int len)
off_t FileBase::seek(upx_int64_t off64, int whence)
{
(void) mem_size(1, off64 >= 0 ? off64 : -off64); // sanity check
mem_size_assert(1, off64 >= 0 ? off64 : -off64); // sanity check
off_t off = ACC_ICONV(off_t, off64);
if (!isOpen())
throwIOException("bad seek 1");
@@ -406,7 +406,7 @@ void OutputFile::rewrite(const void *buf, int len)
off_t OutputFile::seek(upx_int64_t off64, int whence)
{
(void) mem_size(1, off64 >= 0 ? off64 : -off64); // sanity check
mem_size_assert(1, off64 >= 0 ? off64 : -off64); // sanity check
off_t off = ACC_ICONV(off_t, off64);
assert(!opt->to_stdout);
switch (whence) {
+16 -16
View File
@@ -52,7 +52,7 @@ size_t mem_size(upx_uint64_t element_size, upx_uint64_t n, upx_uint64_t extra)
size_t mem_size_get_n(upx_uint64_t element_size, upx_uint64_t n)
{
(void) mem_size(element_size, n); // check
mem_size_assert(element_size, n);
return ACC_ICONV(size_t, n); // return n
}
@@ -90,29 +90,29 @@ int ptr_diff(const char *p1, const char *p2)
/*************************************************************************
// bool use_mcheck()
// bool use_simple_mcheck()
**************************************************************************/
#if defined(__SANITIZE_ADDRESS__)
__acc_static_forceinline bool use_mcheck() { return false; }
__acc_static_forceinline bool use_simple_mcheck() { return false; }
#elif (WITH_VALGRIND) && defined(RUNNING_ON_VALGRIND)
static int use_mcheck_flag = -1;
__acc_static_noinline void use_mcheck_init()
static int use_simple_mcheck_flag = -1;
__acc_static_noinline void use_simple_mcheck_init()
{
use_mcheck_flag = 1;
use_simple_mcheck_flag = 1;
if (RUNNING_ON_VALGRIND) {
use_mcheck_flag = 0;
use_simple_mcheck_flag = 0;
//fprintf(stderr, "upx: detected RUNNING_ON_VALGRIND\n");
}
}
__acc_static_forceinline bool use_mcheck()
__acc_static_forceinline bool use_simple_mcheck()
{
if __acc_unlikely(use_mcheck_flag < 0)
use_mcheck_init();
return (bool) use_mcheck_flag;
if __acc_unlikely(use_simple_mcheck_flag < 0)
use_simple_mcheck_init();
return (bool) use_simple_mcheck_flag;
}
#else
__acc_static_forceinline bool use_mcheck() { return true; }
__acc_static_forceinline bool use_simple_mcheck() { return true; }
#endif
@@ -137,7 +137,7 @@ void MemBuffer::dealloc()
if (b != NULL)
{
checkState();
if (use_mcheck())
if (use_simple_mcheck())
{
// remove magic constants
set_be32(b - 8, 0);
@@ -217,7 +217,7 @@ void MemBuffer::checkState() const
{
if (!b)
throwInternalError("block not allocated");
if (use_mcheck())
if (use_simple_mcheck())
{
if (get_be32(b - 4) != MAGIC1(b))
throwInternalError("memory clobbered before allocated block 1");
@@ -237,12 +237,12 @@ void MemBuffer::alloc(upx_uint64_t size)
assert(b_size == 0);
//
assert(size > 0);
size_t bytes = mem_size(1, size, use_mcheck() ? 32 : 0);
size_t bytes = mem_size(1, size, use_simple_mcheck() ? 32 : 0);
unsigned char *p = (unsigned char *) malloc(bytes);
if (!p)
throwOutOfMemoryException();
b_size = ACC_ICONV(unsigned, size);
if (use_mcheck())
if (use_simple_mcheck())
{
b = p + 16;
// store magic constants to detect buffer overruns
+4
View File
@@ -63,6 +63,10 @@ int mem_replace(void *b, int blen, const void *what, int wlen, const void *r);
size_t mem_size(upx_uint64_t element_size, upx_uint64_t n, upx_uint64_t extra = 0);
size_t mem_size_get_n(upx_uint64_t element_size, upx_uint64_t n);
inline void mem_size_assert(upx_uint64_t element_size, upx_uint64_t n, upx_uint64_t extra = 0) {
(void) mem_size(element_size, n, extra); // sanity check
}
bool mem_size_valid(upx_uint64_t element_size, upx_uint64_t n, upx_uint64_t extra = 0);
bool mem_size_valid_bytes(upx_uint64_t bytes);