From 71aa7f6e5bf2cfefa7b6a4e16556eb079b5c762b Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 20 Jan 2012 20:14:01 -0800 Subject: Tidy up and fix stupid bugs (that Valgrind missed...) --- libcrystfel/src/peaks.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/libcrystfel/src/peaks.c b/libcrystfel/src/peaks.c index f1021fdf..0cbce55f 100644 --- a/libcrystfel/src/peaks.c +++ b/libcrystfel/src/peaks.c @@ -553,20 +553,22 @@ static int compare_resolution(const void *av, const void *bv) } static struct integr_ind *sort_reflections(RefList *list, UnitCell *cell, - int *n) + int *np) { struct integr_ind *il; Reflection *refl; RefListIterator *iter; - int i; + int i, n; - *n = num_reflections(list); + n = num_reflections(list); + *np = 0; /* For now */ - if ( *n == 0 ) return NULL; + if ( n == 0 ) return NULL; - il = calloc(*n, sizeof(struct integr_ind)); + il = calloc(n, sizeof(struct integr_ind)); if ( il == NULL ) return NULL; + i = 0; for ( refl = first_refl(list, &iter); refl != NULL; refl = next_refl(refl, iter) ) @@ -584,11 +586,12 @@ static struct integr_ind *sort_reflections(RefList *list, UnitCell *cell, il[i].refl = refl; i++; - assert(i < *n); + assert(i <= n); } - qsort(il, *n, sizeof(struct integr_ind), compare_resolution); + qsort(il, n, sizeof(struct integr_ind), compare_resolution); + *np = n; return il; } -- cgit v1.2.3