summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2015-05-19 21:09:11 +0200
committerLars-Dominik Braun <lars@6xq.net>2015-05-19 21:09:11 +0200
commit5d68b4d6b6cea967ae015e3c011afb6c3e17bf5f (patch)
treebbc403650354f7b54fcd5c6ce2b7a0f43ca8c7e3
parent179075df17fd5c30d4a8a5984c1637ab67433248 (diff)
downloadpucket-5d68b4d6b6cea967ae015e3c011afb6c3e17bf5f.tar.gz
pucket-5d68b4d6b6cea967ae015e3c011afb6c3e17bf5f.tar.bz2
pucket-5d68b4d6b6cea967ae015e3c011afb6c3e17bf5f.zip
Fix out of bounds detection
unsigned int works, because the greater than check catches the overflow, but it’s obviously not correct.
-rw-r--r--rect.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/rect.c b/rect.c
index 98060bd..371e5c3 100644
--- a/rect.c
+++ b/rect.c
@@ -72,6 +72,7 @@ static void iter_thread (flam3_genome * const input_genome,
volatile bool * const stopped) {
randctx rc;
rand_seed (&rc);
+ const unsigned int w = bucket->dim[0], h = bucket->dim[1];
flam3_genome genome;
memset (&genome, 0, sizeof (genome));
@@ -118,16 +119,13 @@ static void iter_thread (flam3_genome * const input_genome,
for (unsigned int j = 0; j < samples; j++) {
const double4 p = iter_storage[j];
- const double2 origpos = (double2) { p[0], p[1] };
- const double2 transpos = apply_affine (origpos, c->camera);
- const unsigned int x = floor (transpos[0]);
- const unsigned int y = floor (transpos[1]);
+ const double2 origpos = (double2) { p[0], p[1] },
+ transpos = apply_affine (origpos, c->camera);
+ const signed int x = floor (transpos[0]), y = floor (transpos[1]);
/* Skip if out of bounding box or invisible */
- if (x >= 0 && x < bucket->dim[0] &&
- y >= 0 && y < bucket->dim[1] &&
- p[3] > 0) {
- const size_t ix = x + bucket->dim[0] * y;
+ if (x >= 0 && x < w && y >= 0 && y < h && p[3] > 0) {
+ const size_t ix = x + w * y;
#if HAVE_BUILTIN_PREFETCH
/* prefetch for reading (0) with no locality (0). This (partially)
* hides the load latency for the += operation at the end of this