Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fatal crash on 64 bit Linux #687

Merged
merged 2 commits into from
Jan 6, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/lib/openjp2/opj_malloc.c
Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down Expand Up @@ -32,6 +32,10 @@
#define OPJ_SKIP_POISON
#include "opj_includes.h"

#if defined(OPJ_HAVE_MALLOC_H) && defined(OPJ_HAVE_MEMALIGN)
# include <malloc.h>
#endif

#ifndef SIZE_MAX
# define SIZE_MAX ((size_t) -1)
#endif
Expand Down Expand Up @@ -68,7 +72,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--;
Expand All @@ -78,7 +82,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 *)));

Expand Down Expand Up @@ -151,7 +155,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) {
Expand Down