percentage-of-group: fix uninitialized array vh (#15106)
fix uninitialized array vh
Costa Tsaousis committed
May 27, 2023 at 06:25 UTC
6dbbabee8825819ec588b9d389fac1c5e13d7099
1 file changed
+12
-17
web/api/queries/query.c
+12
-17
@@ -2764,19 +2764,16 @@ static RRDR *rrd2rrdr_group_by_initialize(ONEWAYALLOC *owa, QUERY_TARGET *qt) {
2764
}
2765
2766
// make sure there are valid group-by methods
2767
- bool query_has_percentage_of_group = false;
2768
- for(size_t g = 0; g < MAX_QUERY_GROUP_BY_PASSES - 1 ;g++) {
2767
+ for(size_t g = 0; g < MAX_QUERY_GROUP_BY_PASSES ;g++) {
2768
if(!(qt->request.group_by[g].group_by & SUPPORTED_GROUP_BY_METHODS))
2769
qt->request.group_by[g].group_by = (g == 0) ? RRDR_GROUP_BY_DIMENSION : RRDR_GROUP_BY_NONE;
2771
-
2772
- if(qt->request.group_by[g].group_by & RRDR_GROUP_BY_PERCENTAGE_OF_INSTANCE)
2773
- query_has_percentage_of_group = true;
2774
-
2775
- if(qt->request.group_by[g].aggregation == RRDR_GROUP_BY_FUNCTION_PERCENTAGE)
2776
- query_has_percentage_of_group = true;
2770
}
2771
2779
- // merge all group-by options to upper levels
2772
+ bool query_has_percentage_of_group = query_target_has_percentage_of_group(qt);
2773
+
2774
+ // merge all group-by options to upper levels,
2775
+ // so that the top level has all the groupings of the inner levels,
2776
+ // and each subsequent level has all the groupings of its inner levels.
2777
for(size_t g = 0; g < MAX_QUERY_GROUP_BY_PASSES - 1 ;g++) {
2778
if(qt->request.group_by[g].group_by == RRDR_GROUP_BY_NONE)
2779
continue;
@@ -2925,8 +2922,8 @@ static RRDR *rrd2rrdr_group_by_initialize(ONEWAYALLOC *owa, QUERY_TARGET *qt) {
2922
qm->status |= RRDR_DIMENSION_GROUPED;
2923
2924
if(query_has_percentage_of_group)
2928
- // when the query has percentage of instance
2929
- // there will be no hidden dimensions in the final query
2925
+ // when the query has percentage of group
2926
+ // there will be no hidden dimensions in the final query,
2927
// so we have to remove the hidden flag from all dimensions
2928
entries[pos].od |= qm->status & ~RRDR_DIMENSION_HIDDEN;
2929
else
@@ -2944,12 +2941,10 @@ static RRDR *rrd2rrdr_group_by_initialize(ONEWAYALLOC *owa, QUERY_TARGET *qt) {
2941
qt->id, qt->window.after, qt->window.before, added, qt->window.points);
2942
goto cleanup;
2943
}
2947
-
2948
- bool hidden_dimension_on_percentage_of_group = hidden_dimensions && ((group_by & RRDR_GROUP_BY_PERCENTAGE_OF_INSTANCE) || (aggregation_method == RRDR_GROUP_BY_FUNCTION_PERCENTAGE));
2949
-
2950
- // prevent double cleanup in case of error
2944
+ // prevent double free at cleanup in case of error
2945
added = 0;
2946
2947
+ // link this RRDR
2948
if(!last_r)
2949
first_r = last_r = r;
2950
else
@@ -2964,7 +2959,7 @@ static RRDR *rrd2rrdr_group_by_initialize(ONEWAYALLOC *owa, QUERY_TARGET *qt) {
2959
r->gbc = onewayalloc_callocz(owa, r->n * r->d, sizeof(*r->gbc));
2960
r->dqp = onewayalloc_callocz(owa, r->d, sizeof(STORAGE_POINT));
2961
2967
- if(hidden_dimension_on_percentage_of_group)
2962
+ if(hidden_dimensions && ((group_by & RRDR_GROUP_BY_PERCENTAGE_OF_INSTANCE) || (aggregation_method == RRDR_GROUP_BY_FUNCTION_PERCENTAGE)))
2963
// this is where we are going to group the hidden dimensions
2964
r->vh = onewayalloc_mallocz(owa, r->n * r->d * sizeof(*r->vh));
2965
@@ -3016,7 +3011,7 @@ static RRDR *rrd2rrdr_group_by_initialize(ONEWAYALLOC *owa, QUERY_TARGET *qt) {
3011
co[d] = RRDR_VALUE_EMPTY;
3012
3013
if(vh)
3019
- *vh = NAN;
3014
+ vh[d] = NAN;
3015
}
3016
}
3017
}