diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2015-05-19 21:09:11 +0200 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2015-05-19 21:09:11 +0200 |
commit | 5d68b4d6b6cea967ae015e3c011afb6c3e17bf5f (patch) | |
tree | bbc403650354f7b54fcd5c6ce2b7a0f43ca8c7e3 | |
parent | 179075df17fd5c30d4a8a5984c1637ab67433248 (diff) | |
download | pucket-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.c | 14 |
1 files changed, 6 insertions, 8 deletions
@@ -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 |