Skip to content
Snippets Groups Projects
Verified Commit e2d41a4a authored by Joey Reinhart's avatar Joey Reinhart
Browse files

NULL checking

parent 4d6a7914
Branches master
No related tags found
No related merge requests found
Pipeline #558411 failed with stages
in 1 hour, 2 minutes, and 49 seconds
......@@ -101,10 +101,12 @@ static inline void *dav1d_alloc_aligned_internal(const size_t sz, const size_t a
// must be an integral multiple of alignment.
return aligned_alloc(align, ROUND_UP(sz, align));
#else
char *ptr = (char *)malloc(sz + align + sizeof(void *));
char *result = (char *)(((size_t)ptr + sizeof(void *) + align - 1) & ~(align - 1));
((char **)result)[-1] = ptr;
return result;
void *const buf = malloc(sz + align + sizeof(void *));
if (!buf) return NULL;
void *const ptr = (void *)(((uintptr_t)buf + sizeof(void *) + align - 1) & ~(align - 1));
((void **)ptr)[-1] = buf;
return ptr;
#endif
}
......@@ -114,7 +116,7 @@ static inline void dav1d_free_aligned_internal(void *ptr) {
#elif HAVE_POSIX_MEMALIGN || HAVE_MEMALIGN || HAVE_ALIGNED_ALLOC
free(ptr);
#else
free(((void **)ptr)[-1]);
if (ptr) free(((void **)ptr)[-1]);
#endif
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment