diff options
Diffstat (limited to 'extern/libopenjpeg/opj_malloc.h')
-rw-r--r-- | extern/libopenjpeg/opj_malloc.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/extern/libopenjpeg/opj_malloc.h b/extern/libopenjpeg/opj_malloc.h index aef2ee3b8c9..5007b0c9e23 100644 --- a/extern/libopenjpeg/opj_malloc.h +++ b/extern/libopenjpeg/opj_malloc.h @@ -1,4 +1,9 @@ /* + * The copyright in this software is being made available under the 2-clauses + * BSD License, included below. This software may be subject to other third + * party and contributor rights, including patent rights, and no such rights + * are granted under this license. + * * Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2007, Callum Lerwick <seg@haxxed.com> * All rights reserved. @@ -48,8 +53,13 @@ Allocate an uninitialized memory block #ifdef ALLOC_PERF_OPT void * OPJ_CALLCONV opj_malloc(size_t size); #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) #endif +#endif /** Allocate a memory block with elements initialized to 0 @@ -60,8 +70,13 @@ Allocate a memory block with elements initialized to 0 #ifdef ALLOC_PERF_OPT void * OPJ_CALLCONV opj_calloc(size_t _NumOfElements, size_t _SizeOfElements); #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) #endif +#endif /** Allocate memory aligned to a 16 byte boundry @@ -139,8 +154,13 @@ Reallocate memory blocks. #ifdef ALLOC_PERF_OPT void * OPJ_CALLCONV opj_realloc(void * m, size_t s); #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) #endif +#endif /** Deallocates or frees a memory block. |