aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2012-01-20 20:14:01 -0800
committerThomas White <taw@physics.org>2012-02-22 15:27:44 +0100
commit71aa7f6e5bf2cfefa7b6a4e16556eb079b5c762b (patch)
treed47f8f1ea304479720a3889632c53a312dbe6337
parentae51e75490daf47e2deefe83e72a1f5c092fa023 (diff)
Tidy up and fix stupid bugs (that Valgrind missed...)
-rw-r--r--libcrystfel/src/peaks.c17
1 files 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;
}