aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortaw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1>2007-08-28 22:12:04 +0000
committertaw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1>2007-08-28 22:12:04 +0000
commit98b90bde11512c417a1db63029a8a151c3aea975 (patch)
tree3ac089787baa9f38d6bae53ede6e686e4b2640ec
parent50a75cc5458ba553f5cdcede6c9699f7a0347377 (diff)
Cap the length of a reflection list to avoid chewing memory if the peak detection is inadequate
git-svn-id: svn://cook.msm.cam.ac.uk:745/diff-tomo/dtr@83 bf6ca9ba-c028-0410-8290-897cf20841d1
-rw-r--r--src/ipr.c4
-rw-r--r--src/reflections.c15
-rw-r--r--src/reflections.h3
3 files changed, 21 insertions, 1 deletions
diff --git a/src/ipr.c b/src/ipr.c
index c8f9d8a..bc58788 100644
--- a/src/ipr.c
+++ b/src/ipr.c
@@ -221,7 +221,9 @@ static ReflectionContext *ipr_generate(ControlContext *ctx, Basis *basis) {
if ( ( x*x + y*y + z*z ) <= max_res*max_res ) {
Reflection *ref;
ref = reflection_add(ordered, x, y, z, 1, REFLECTION_GENERATED);
- ref->h = h; ref->k = k; ref->l = l;
+ if ( ref ) { /* Check it's not NULL */
+ ref->h = h; ref->k = k; ref->l = l;
+ }
}
}
diff --git a/src/reflections.c b/src/reflections.c
index 4d9f448..d53af10 100644
--- a/src/reflections.c
+++ b/src/reflections.c
@@ -29,12 +29,16 @@ static void reflection_addfirst(ReflectionContext *reflectionctx) {
reflectionctx->reflections->z = 0;
reflectionctx->reflections->type = REFLECTION_CENTRAL;
reflectionctx->last_reflection = reflectionctx->reflections;
+ reflectionctx->n_reflections = 1;
+ reflectionctx->list_capped = 0;
}
ReflectionContext *reflection_init() {
ReflectionContext *reflectionctx = malloc(sizeof(ReflectionContext));
reflection_addfirst(reflectionctx);
+ reflectionctx->n_reflections = 0;
+ reflectionctx->list_capped = 0;
return reflectionctx;
@@ -49,6 +53,8 @@ void reflection_clear(ReflectionContext *reflectionctx) {
reflection = next;
} while ( reflection );
+ reflectionctx->n_reflections = 0;
+ reflectionctx->list_capped = 0;
reflection_addfirst(reflectionctx);
}
@@ -63,6 +69,15 @@ Reflection *reflection_add(ReflectionContext *reflectionctx, double x, double y,
Reflection *new_reflection;
+ if ( reflectionctx->list_capped ) return NULL;
+
+ if ( reflectionctx->n_reflections > 1e7 ) {
+ fprintf(stderr, "More than 10 million reflections on list. I think this is silly.\n");
+ fprintf(stderr, "No further reflections will be stored. Go and fix the peak detection.\n");
+ reflectionctx->list_capped = 1;
+ }
+ reflectionctx->n_reflections++;
+
new_reflection = malloc(sizeof(Reflection));
new_reflection->next = NULL;
new_reflection->x = x;
diff --git a/src/reflections.h b/src/reflections.h
index dc15d88..571f754 100644
--- a/src/reflections.h
+++ b/src/reflections.h
@@ -61,6 +61,9 @@ typedef struct rctx_struct {
Reflection *reflections;
Reflection *last_reflection;
+ unsigned int n_reflections;
+ unsigned int list_capped;
+
Basis *basis;
} ReflectionContext;