fix undefined (#19960)
do not create empty rrdr Co-authored-by: Ilya Mashchenko <ilya@netdata.cloud>
Costa Tsaousis committed
Mar 25, 2025 at 13:55 UTC
032c3166e39ab333bf4803af40eb01d3535ec7a9
1 file changed
+19
-17
src/web/api/queries/rrdr.c
+19
-17
@@ -108,9 +108,19 @@ inline void rrdr_free(ONEWAYALLOC *owa, RRDR *r) {
108
}
109
110
RRDR *rrdr_create(ONEWAYALLOC *owa, QUERY_TARGET *qt, size_t dimensions, size_t points) {
111
- if(unlikely(!qt))
111
+ if(unlikely(!owa || !qt))
112
return NULL;
113
114
+ if(unlikely(!dimensions)) {
115
+ internal_error(true, "Attempted to create an RRDR with 0 dimensions.");
116
+ return NULL;
117
+ }
118
+
119
+ if(unlikely(!points)) {
120
+ internal_error(true, "Attempted to create an RRDR with 0 points.");
121
+ return NULL;
122
+ }
123
+
124
// create the rrdr
125
RRDR *r = onewayalloc_callocz(owa, 1, sizeof(RRDR));
126
r->internal.owa = owa;
@@ -122,22 +132,14 @@ RRDR *rrdr_create(ONEWAYALLOC *owa, QUERY_TARGET *qt, size_t dimensions, size_t
132
r->d = (int)dimensions;
133
r->n = (int)points;
134
125
- if(points && dimensions) {
126
- r->v = onewayalloc_mallocz(owa, points * dimensions * sizeof(NETDATA_DOUBLE));
127
- r->o = onewayalloc_mallocz(owa, points * dimensions * sizeof(RRDR_VALUE_FLAGS));
128
- r->ar = onewayalloc_mallocz(owa, points * dimensions * sizeof(NETDATA_DOUBLE));
129
- }
130
-
131
- if(points) {
132
- r->t = onewayalloc_callocz(owa, points, sizeof(time_t));
133
- }
134
-
135
- if(dimensions) {
136
- r->od = onewayalloc_mallocz(owa, dimensions * sizeof(RRDR_DIMENSION_FLAGS));
137
- r->di = onewayalloc_callocz(owa, dimensions, sizeof(STRING *));
138
- r->dn = onewayalloc_callocz(owa, dimensions, sizeof(STRING *));
139
- r->du = onewayalloc_callocz(owa, dimensions, sizeof(STRING *));
140
- }
135
+ r->v = onewayalloc_mallocz(owa, points * dimensions * sizeof(NETDATA_DOUBLE));
136
+ r->o = onewayalloc_mallocz(owa, points * dimensions * sizeof(RRDR_VALUE_FLAGS));
137
+ r->ar = onewayalloc_mallocz(owa, points * dimensions * sizeof(NETDATA_DOUBLE));
138
+ r->t = onewayalloc_callocz(owa, points, sizeof(time_t));
139
+ r->od = onewayalloc_mallocz(owa, dimensions * sizeof(RRDR_DIMENSION_FLAGS));
140
+ r->di = onewayalloc_callocz(owa, dimensions, sizeof(STRING *));
141
+ r->dn = onewayalloc_callocz(owa, dimensions, sizeof(STRING *));
142
+ r->du = onewayalloc_callocz(owa, dimensions, sizeof(STRING *));
143
144
r->view.group = 1;
145
r->view.update_every = 1;