summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2015-02-14 15:15:10 +0100
committerLars-Dominik Braun <lars@6xq.net>2015-05-02 21:36:45 +0200
commita17efd79d34285a695bf2044f65acf6b7637f98a (patch)
tree17e122f46bb46b0172d2e1e2343880de6a5d0e5c
parentbae3078a59ffa404371f2095885bcf06984efad2 (diff)
downloadpucket-a17efd79d34285a695bf2044f65acf6b7637f98a.tar.gz
pucket-a17efd79d34285a695bf2044f65acf6b7637f98a.tar.bz2
pucket-a17efd79d34285a695bf2044f65acf6b7637f98a.zip
Correctly align malloc’d vector arrays
Fixes segfault with -march=native
-rw-r--r--flam3.c4
-rw-r--r--rect.c17
2 files changed, 17 insertions, 4 deletions
diff --git a/flam3.c b/flam3.c
index 4564b3f..c8f43ce 100644
--- a/flam3.c
+++ b/flam3.c
@@ -35,6 +35,7 @@
#include <unistd.h>
#endif
#include <errno.h>
+#include <assert.h>
#include <pthread.h>
@@ -3259,7 +3260,8 @@ int flam3_estimate_bounding_box(flam3_genome *cp, double eps, int nsamples,
if (nsamples <= 0) nsamples = 10000;
- points = (double4 *) malloc(sizeof(double4) * nsamples);
+ int ret = posix_memalign ((void **) &points, sizeof (*points), sizeof(*points) * nsamples);
+ assert (ret == 0 && points != NULL);
const double4 start = (double4) { rand_d11(rc), rand_d11(rc), 0.0, 0.0 };
if (prepare_precalc_flags(cp))
diff --git a/rect.c b/rect.c
index 7e45e16..e566647 100644
--- a/rect.c
+++ b/rect.c
@@ -17,6 +17,7 @@
*/
#include <assert.h>
+#include <stdlib.h>
#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) {