From 3f535535243944117ac6fe7c67b394f036c09baa Mon Sep 17 00:00:00 2001 From: Botond Baranyi <botond.baranyi@ericsson.com> Date: Thu, 21 Jul 2016 16:57:10 +0200 Subject: [PATCH] fixed compilation errors when DEBUG is switched on Change-Id: I4e904363dabff40b4653a61bac548a494d5075f2 Signed-off-by: Botond Baranyi <botond.baranyi@ericsson.com> --- common/dbgnew.hh | 11 ++++++++++- common/memory.h | 2 +- common/new.cc | 12 +++++++++++- core/Integer.cc | 6 +++--- core/LoggerPluginManager.cc | 2 -- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/common/dbgnew.hh b/common/dbgnew.hh index c3164531b..2f9ddbb6a 100644 --- a/common/dbgnew.hh +++ b/common/dbgnew.hh @@ -19,6 +19,8 @@ #ifdef MEMORY_DEBUG +#include <new> + class debug_new_counter_t { static int count; @@ -40,8 +42,15 @@ static debug_new_counter_t debug_new_counter; void* operator new(size_t size, const char* file, int line); void* operator new[](size_t size, const char* file, int line); +// TODO: these might be GCC version dependant +void* operator new(size_t size, const std::nothrow_t&, const char* file, int line); +void* operator new[](size_t size, const std::nothrow_t&, const char* file, int line); + +inline void* operator new(size_t, void* __p, const char*, int) { return __p; } +inline void* operator new[](size_t, void* __p, const char*, int) { return __p; } + // Redirect "normal" new to memory-tracking placement new. -#define new new(__FILE__, __LINE__) +#define new(...) new(__VA_ARGS__, __FILE__, __LINE__) #endif // MEMORY_DEBUG diff --git a/common/memory.h b/common/memory.h index 9ae9d88c7..6f4a3f807 100644 --- a/common/memory.h +++ b/common/memory.h @@ -143,7 +143,7 @@ extern "C" { #if defined(__GNUC__) && __GNUC__ < 3 # define mprintf(f, args...) mprintf_dbg(__FILE__, __LINE__, f, ## args) #else -# define mprintf(f,...) mprintf_dbg(__FILE__, __LINE__, f, __VA_ARGS__) +# define mprintf(...) mprintf_dbg(__FILE__, __LINE__, __VA_ARGS__) #endif #endif diff --git a/common/new.cc b/common/new.cc index 1b1c43a2d..fa26100a4 100644 --- a/common/new.cc +++ b/common/new.cc @@ -13,7 +13,6 @@ ******************************************************************************/ #include "dbgnew.hh" #include <stddef.h> -#include <new> #undef new @@ -56,6 +55,17 @@ void* operator new[](size_t size, const char* file, int line) else return Malloc_dbg(file, line, size); } +void* operator new(size_t size, const std::nothrow_t&, const char* file, int line) +{ + return Malloc_dbg(file, line, size); +} + +void* operator new[](size_t size, const std::nothrow_t&, const char* file, int line) +{ + if (size == 0) return &dummy; + else return Malloc_dbg(file, line, size); +} + int debug_new_counter_t::count = 0; // initial value #if defined(__CYGWIN__) || defined(INTERIX) diff --git a/core/Integer.cc b/core/Integer.cc index 9ac1c32d8..52f884e0e 100644 --- a/core/Integer.cc +++ b/core/Integer.cc @@ -598,11 +598,11 @@ long long int INTEGER::get_long_long_val() const // It feels so bad accessing a BIGNUM directly, but faster than string // conversion... // I know, I had to fix this... Bence - if (BN_num_bytes(val.openssl) <= sizeof(BN_ULONG)) { + if ((size_t)BN_num_bytes(val.openssl) <= sizeof(BN_ULONG)) { return !is_negative ? BN_get_word(val.openssl) : -BN_get_word(val.openssl); } - unsigned num_bytes = BN_num_bytes(val.openssl); + int num_bytes = BN_num_bytes(val.openssl); unsigned char* tmp = (unsigned char*)Malloc(num_bytes * sizeof(unsigned char)); BN_bn2bin(val.openssl, tmp); ret_val = tmp[0] & 0xff; @@ -1308,7 +1308,7 @@ int INTEGER::RAW_encode_openssl(const TTCN_Typedescriptor_t& p_td, // Conversion to 2's complement. if (twos_compl) { BN_set_negative(D, 0); - unsigned num_bytes = BN_num_bytes(D); + int num_bytes = BN_num_bytes(D); unsigned char* tmp = (unsigned char*)Malloc(num_bytes * sizeof(unsigned char)); BN_bn2bin(D, tmp); for (int a = 0; a < num_bytes; a++) tmp[a] = ~tmp[a]; diff --git a/core/LoggerPluginManager.cc b/core/LoggerPluginManager.cc index 10a7fd7ec..09c427981 100644 --- a/core/LoggerPluginManager.cc +++ b/core/LoggerPluginManager.cc @@ -1799,8 +1799,6 @@ LoggerPlugin *LoggerPluginManager::find_plugin(const char *name) #undef new #endif -inline void * operator new (size_t, void * p) throw() { return p ; } - LoggerPluginManager::ActiveEvent::ActiveEvent(bool fake_event, event_destination_t dest) : event_() , event_str_(NULL) -- GitLab