From 79b1c4cc85e5d1709cdb831561ba4927ea673514 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Wed, 6 Jan 2016 21:34:59 +0100 Subject: [PATCH 1/2] Fix whitespace issues in opj_malloc.c Some lines ended with spaces. Remove them. Signed-off-by: Stefan Weil --- src/lib/openjp2/opj_malloc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib/openjp2/opj_malloc.c b/src/lib/openjp2/opj_malloc.c index 3c8cedf7..e91b660e 100644 --- a/src/lib/openjp2/opj_malloc.c +++ b/src/lib/openjp2/opj_malloc.c @@ -1,6 +1,6 @@ /* - * 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 + * 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. * @@ -68,7 +68,7 @@ static INLINE void *opj_aligned_alloc_n(size_t alignment, size_t size) /* * Generic aligned malloc implementation. * Uses size_t offset for the integer manipulation of the pointer, - * as uintptr_t is not available in C89 to do + * as uintptr_t is not available in C89 to do * bitwise operations on the pointer itself. */ alignment--; @@ -78,7 +78,7 @@ static INLINE void *opj_aligned_alloc_n(size_t alignment, size_t size) /* Room for padding and extra pointer stored in front of allocated area */ size_t overhead = alignment + sizeof(void *); - + /* let's be extra careful */ assert(alignment <= (SIZE_MAX - sizeof(void *))); @@ -151,7 +151,7 @@ static INLINE void *opj_aligned_realloc_n(void *ptr, size_t alignment, size_t ne if (new_size > SIZE_MAX - overhead) { return NULL; } - + oldmem = ((void**) ptr)[-1]; newmem = (OPJ_UINT8*)realloc(oldmem, new_size + overhead); if (newmem == NULL) { From 9cad6bc1f68be54189c6db8a7fcef6f994daf891 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Wed, 6 Jan 2016 21:34:59 +0100 Subject: [PATCH 2/2] Fix fatal crash on 64 bit Linux MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By default, OpenJPEG uses the function memalign to allocate aligned memory on Linux systems. That function needs malloc.h which was missing. This results in a compiler warning: openjpeg/src/lib/openjp2/opj_malloc.c:63:3: warning: implicit declaration of function ‘memalign’ [-Wimplicit-function-declaration] On hosts where sizeof(int) < sizeof(void *) the return value of memalign will be truncated which results in an invalid pointer. That caused "make test" to produce lots of segmentation faults when running on a 64 bit Linux host. Signed-off-by: Stefan Weil --- src/lib/openjp2/opj_malloc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/openjp2/opj_malloc.c b/src/lib/openjp2/opj_malloc.c index e91b660e..e04db912 100644 --- a/src/lib/openjp2/opj_malloc.c +++ b/src/lib/openjp2/opj_malloc.c @@ -32,6 +32,10 @@ #define OPJ_SKIP_POISON #include "opj_includes.h" +#if defined(OPJ_HAVE_MALLOC_H) && defined(OPJ_HAVE_MEMALIGN) +# include +#endif + #ifndef SIZE_MAX # define SIZE_MAX ((size_t) -1) #endif