Skip to content

Commit

Permalink
r.stats.quantile: sync to r.quantile (#2323)
Browse files Browse the repository at this point in the history
* sync correctly to r.quantile
* fix segfault

Fixes #2259
  • Loading branch information
metzm committed Apr 26, 2022
1 parent 1c7f667 commit d76d518
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions raster/r.stats.quantile/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct basecat
size_t num_values;
DCELL min, max, slot_size;
int num_slots;
unsigned char *slot_bins;
unsigned short *slot_bins;
int num_bins_alloc;
int num_bins_used;
struct bin *bins;
Expand Down Expand Up @@ -160,14 +160,16 @@ static void get_slot_counts(int basefile, int coverfile)
if (bc->max <= bc->min)
continue;

bc->num_slots = num_slots;
/* minimum 1000 values per slot to reduce memory consumption */
num_slots_max = bc->total / 1000;
if (num_slots_max < 1)
num_slots_max = 1;
if (bc->num_slots > num_slots_max) {
bc->num_slots = num_slots_max;
}

bc->slots = G_calloc(bc->num_slots, sizeof(unsigned int));
bc->slots = G_calloc(bc->num_slots, sizeof(size_t));
bc->slot_size = (bc->max - bc->min) / bc->num_slots;
}

Expand Down Expand Up @@ -220,7 +222,7 @@ static void initialize_bins(void)

bc->num_bins_alloc = num_quants * 2;
bc->bins = G_calloc(bc->num_bins_alloc, sizeof(struct bin));
bc->slot_bins = G_calloc(bc->num_slots, sizeof(unsigned char));
bc->slot_bins = G_calloc(bc->num_slots, sizeof(unsigned short));

next = get_quantile(bc, quant);

Expand Down

0 comments on commit d76d518

Please sign in to comment.