aboutsummaryrefslogtreecommitdiff
path: root/data/diffraction.cl
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2010-02-19 14:39:39 +0100
committerThomas White <taw@physics.org>2010-02-19 14:39:39 +0100
commitbea7274dc2523829d4091ed79c7db6cba4d63bfb (patch)
tree2197be444a32cd90a7c02d3dfb650d7ba432dbea /data/diffraction.cl
parent0d471a2f7722981b0d766d040a1c69424406f6b6 (diff)
Don't overrun bounds of sfac buffer
This results in Bad Stuff happening.
Diffstat (limited to 'data/diffraction.cl')
-rw-r--r--data/diffraction.cl18
1 files changed, 13 insertions, 5 deletions
diff --git a/data/diffraction.cl b/data/diffraction.cl
index bcdaa726..a861b159 100644
--- a/data/diffraction.cl
+++ b/data/diffraction.cl
@@ -10,7 +10,7 @@
*/
-#define INDMAX 30
+#define INDMAX 70
#define IDIM (INDMAX*2 +1)
@@ -99,12 +99,17 @@ float lattice_factor(float16 cell, float4 q)
float2 get_sfac(global float2 *sfacs, float16 cell, float4 q)
{
- signed int h, k, l;
+ float hf, kf, lf;
+ int h, k, l;
int idx;
- h = rint(cell.s0*q.x + cell.s1*q.y + cell.s2*q.z); /* h */
- k = rint(cell.s3*q.x + cell.s4*q.y + cell.s5*q.z); /* k */
- l = rint(cell.s6*q.x + cell.s7*q.y + cell.s8*q.z); /* l */
+ hf = cell.s0*q.x + cell.s1*q.y + cell.s2*q.z; /* h */
+ kf = cell.s3*q.x + cell.s4*q.y + cell.s5*q.z; /* k */
+ lf = cell.s6*q.x + cell.s7*q.y + cell.s8*q.z; /* l */
+
+ h = round(hf);
+ k = round(kf);
+ l = round(lf);
if ( (abs(h) > INDMAX) || (abs(k) > INDMAX) || (abs(l) > INDMAX) ) {
return 100.0;
@@ -114,7 +119,10 @@ float2 get_sfac(global float2 *sfacs, float16 cell, float4 q)
if ( k < 0 ) k += IDIM;
if ( l < 0 ) l += IDIM;
+ if ( (h>=IDIM) || (k>=IDIM) || (l>=IDIM) ) return 100.0;
+
idx = h + (IDIM*k) + (IDIM*IDIM*l);
+
return sfacs[idx];
}