diff options
author | taw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1> | 2007-08-28 22:12:04 +0000 |
---|---|---|
committer | taw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1> | 2007-08-28 22:12:04 +0000 |
commit | 98b90bde11512c417a1db63029a8a151c3aea975 (patch) | |
tree | 3ac089787baa9f38d6bae53ede6e686e4b2640ec /src/reflections.c | |
parent | 50a75cc5458ba553f5cdcede6c9699f7a0347377 (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
Diffstat (limited to 'src/reflections.c')
-rw-r--r-- | src/reflections.c | 15 |
1 files changed, 15 insertions, 0 deletions
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; |