Fixed seg fault
This commit is contained in:
@@ -84,7 +84,7 @@ int read_clusters_with_cut(FILE *fp, int64_t n_clusters, Cluster *buf, int *n_le
|
||||
if (good) {
|
||||
ptr++;
|
||||
nph_read++;
|
||||
*n_left--;
|
||||
(*n_left)--;
|
||||
}
|
||||
if (nph_read >= n_clusters)
|
||||
break;
|
||||
@@ -94,8 +94,10 @@ int read_clusters_with_cut(FILE *fp, int64_t n_clusters, Cluster *buf, int *n_le
|
||||
if (nph_read < n_clusters) {
|
||||
// keep on reading frames and photons until reaching n_clusters
|
||||
while (fread(&iframe, sizeof(iframe), 1, fp)) {
|
||||
//printf("%d\n",nph_read);
|
||||
|
||||
if (fread(&nph, sizeof(nph), 1, fp)) {
|
||||
//printf("** %d\n",nph);
|
||||
*n_left = nph;
|
||||
for (int iph=0; iph<nph; iph++) {
|
||||
// read photons 1 by 1
|
||||
@@ -118,7 +120,7 @@ int read_clusters_with_cut(FILE *fp, int64_t n_clusters, Cluster *buf, int *n_le
|
||||
if (good) {
|
||||
ptr++;
|
||||
nph_read++;
|
||||
*n_left--;
|
||||
(*n_left)--;
|
||||
}
|
||||
if (nph_read >= n_clusters)
|
||||
break;
|
||||
@@ -130,7 +132,7 @@ int read_clusters_with_cut(FILE *fp, int64_t n_clusters, Cluster *buf, int *n_le
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//printf("%d\n",nph_read);
|
||||
assert(nph_read <= n_clusters); // sanity check in debug mode
|
||||
return nph_read;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user