From a17efd79d34285a695bf2044f65acf6b7637f98a Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sat, 14 Feb 2015 15:15:10 +0100 Subject: Correctly align malloc’d vector arrays MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes segfault with -march=native --- rect.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'rect.c') diff --git a/rect.c b/rect.c index 7e45e16..e566647 100644 --- a/rect.c +++ b/rect.c @@ -17,6 +17,7 @@ */ #include +#include #include "private.h" #include "filters.h" @@ -380,14 +381,24 @@ int render_rectangle(flam3_frame *spec, void *out, nbuckets = (long)fic.width * (long)fic.height; - double4 * const buckets = malloc (nbuckets * sizeof (*buckets)); + double4 *buckets; + int ret = posix_memalign ((void **) &buckets, sizeof (*buckets), + nbuckets * sizeof (*buckets)); + assert (ret == 0); assert (buckets != NULL); - double4 * const accumulate = malloc (nbuckets * sizeof (*accumulate)); + double4 *accumulate; + ret = posix_memalign ((void **) &accumulate, sizeof (*accumulate), + nbuckets * sizeof (*accumulate)); + assert (ret == 0); assert (accumulate != NULL); double4 ** const iter_storage = malloc (spec->nthreads * sizeof (*iter_storage)); assert (iter_storage != NULL); for (size_t i = 0; i < spec->nthreads; i++) { - iter_storage[i] = malloc (spec->sub_batch_size * sizeof (*iter_storage[i])); + ret = posix_memalign ((void **) &iter_storage[i], + sizeof (*iter_storage[i]), + spec->sub_batch_size * sizeof (*iter_storage[i])); + assert (ret == 0); + assert (iter_storage[i] != NULL); } if (verbose) { -- cgit v1.2.3