[trunk] Import left over from patch submitted as issue 225 (comment #14)

Update issue 225
This commit is contained in:
Mathieu Malaterre 2014-03-03 11:48:27 +00:00
parent b330c10492
commit 18049fe3e0
1 changed files with 15 additions and 0 deletions

View File

@ -48,8 +48,13 @@ Allocate an uninitialized memory block
#ifdef ALLOC_PERF_OPT #ifdef ALLOC_PERF_OPT
void * OPJ_CALLCONV opj_malloc(size_t size); void * OPJ_CALLCONV opj_malloc(size_t size);
#else #else
/* prevent assertion on overflow for MSVC */
#ifdef _MSC_VER
#define opj_malloc(size) ((size_t)(size) >= (size_t)-0x100 ? NULL : malloc(size))
#else
#define opj_malloc(size) malloc(size) #define opj_malloc(size) malloc(size)
#endif #endif
#endif
/** /**
Allocate a memory block with elements initialized to 0 Allocate a memory block with elements initialized to 0
@ -60,8 +65,13 @@ Allocate a memory block with elements initialized to 0
#ifdef ALLOC_PERF_OPT #ifdef ALLOC_PERF_OPT
void * OPJ_CALLCONV opj_calloc(size_t _NumOfElements, size_t _SizeOfElements); void * OPJ_CALLCONV opj_calloc(size_t _NumOfElements, size_t _SizeOfElements);
#else #else
/* prevent assertion on overflow for MSVC */
#ifdef _MSC_VER
#define opj_calloc(num, size) ((size_t)(num) != 0 && (size_t)(num) >= (size_t)-0x100 / (size_t)(size) ? NULL : calloc(num, size))
#else
#define opj_calloc(num, size) calloc(num, size) #define opj_calloc(num, size) calloc(num, size)
#endif #endif
#endif
/** /**
Allocate memory aligned to a 16 byte boundry Allocate memory aligned to a 16 byte boundry
@ -139,8 +149,13 @@ Reallocate memory blocks.
#ifdef ALLOC_PERF_OPT #ifdef ALLOC_PERF_OPT
void * OPJ_CALLCONV opj_realloc(void * m, size_t s); void * OPJ_CALLCONV opj_realloc(void * m, size_t s);
#else #else
/* prevent assertion on overflow for MSVC */
#ifdef _MSC_VER
#define opj_realloc(m, s) ((size_t)(s) >= (size_t)-0x100 ? NULL : realloc(m, s))
#else
#define opj_realloc(m, s) realloc(m, s) #define opj_realloc(m, s) realloc(m, s)
#endif #endif
#endif
/** /**
Deallocates or frees a memory block. Deallocates or frees a memory block.