]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix sending data to graph command
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 20 Jul 2016 13:53:19 +0000 (14:53 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 20 Jul 2016 13:53:53 +0000 (14:53 +0100)
Issue: #405

src/controller.c

index 5662409d68ba87e9ac830883a7af1f50c4bac95a..2659bd275cb1310a6aaa7255f621aeaf33aa7d00 100644 (file)
@@ -1041,7 +1041,7 @@ rspamd_controller_graph_point (gulong t, gulong step,
 
                for (j = 0; j < step; j++) {
                        yval = acc[i + j * rrd_result->ds_count];
-                       if (isnan(yval)) {
+                       if (isnan (yval)) {
                                nan_cnt++;
                        }
                        else {
@@ -1081,7 +1081,7 @@ rspamd_controller_handle_graph (
        struct rspamd_controller_worker_ctx *ctx;
        rspamd_ftok_t srch, *value;
        struct rspamd_rrd_query_result *rrd_result;
-       gulong i, j, k, start_row, cnt, t, ts, step;
+       gulong i, k, start_row, cnt, t, ts, step;
        gdouble *acc;
        ucl_object_t *res, *elt[4];
        enum {
@@ -1170,24 +1170,25 @@ rspamd_controller_handle_graph (
 
        /* Create window */
        step = (rrd_result->rra_rows / desired_points + 0.5);
+       g_assert (step >= 1);
        acc = g_malloc0 (sizeof (double) * rrd_result->ds_count * step);
 
        for (i = start_row, cnt = 0; cnt < rrd_result->rra_rows;
                        cnt ++) {
-               for (j = 0; j < rrd_result->ds_count; j++) {
-                       if (k < step) {
-                               /* Just update window */
-                               acc[k * rrd_result->ds_count + j] =
-                                               rrd_result->data[i * rrd_result->ds_count + j];
-                               k ++;
-                       }
-                       else {
-                               t = ts * rrd_result->pdp_per_cdp;
 
-                               /* Need a fresh point */
-                               rspamd_controller_graph_point (t, step, rrd_result, acc, elt);
-                               k = 0;
-                       }
+               memcpy (&acc[k * rrd_result->ds_count],
+                               &rrd_result->data[i * rrd_result->ds_count],
+                               sizeof (gdouble) * rrd_result->ds_count);
+
+               if (k < step - 1) {
+                       k ++;
+               }
+               else {
+                       t = ts * rrd_result->pdp_per_cdp;
+
+                       /* Need a fresh point */
+                       rspamd_controller_graph_point (t, step, rrd_result, acc, elt);
+                       k = 0;
                }
 
                if (i == rrd_result->rra_rows - 1) {