]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Do not use static variables in xtr() and ytr() 873/head
authorMatwey V. Kornilov <matwey.kornilov@gmail.com>
Fri, 9 Feb 2018 10:06:39 +0000 (13:06 +0300)
committerMatwey V. Kornilov <matwey.kornilov@gmail.com>
Fri, 9 Feb 2018 10:06:39 +0000 (13:06 +0300)
Using static variables for writting leads to race conditions. In order to keep
scale for axis we introduce x_pixie and y_pixie into image_desc_t.

Signed-off-by: Matwey V. Kornilov <matwey.kornilov@gmail.com>
src/rrd_graph.c
src/rrd_graph.h

index cd63faea6081d42ab5af214f3ff3f83615a7c4a4..0b8179e921fe5b7a754849a0bb33a1a244a8d8be 100644 (file)
@@ -247,13 +247,11 @@ int xtr(
     image_desc_t *im,
     time_t mytime)
 {
-    static double pixie;
-
     if (mytime == 0) {
-        pixie = (double) im->xsize / (double) (im->end - im->start);
+        im->x_pixie = (double) im->xsize / (double) (im->end - im->start);
         return im->xorigin;
     }
-    return (int) ((double) im->xorigin + pixie * (mytime - im->start));
+    return (int) ((double) im->xorigin + im->x_pixie * (mytime - im->start));
 }
 
 /* translate data values into y coordinates */
@@ -261,23 +259,22 @@ double ytr(
     image_desc_t *im,
     double value)
 {
-    static double pixie;
     double    yval;
 
     if (isnan(value)) {
         if (!im->logarithmic)
-            pixie = (double) im->ysize / (im->maxval - im->minval);
+            im->y_pixie = (double) im->ysize / (im->maxval - im->minval);
         else
-            pixie =
+            im->y_pixie =
                 (double) im->ysize / (log10(im->maxval) - log10(im->minval));
         yval = im->yorigin;
     } else if (!im->logarithmic) {
-        yval = im->yorigin - pixie * (value - im->minval);
+        yval = im->yorigin - im->y_pixie * (value - im->minval);
     } else {
         if (value < im->minval) {
             yval = im->yorigin;
         } else {
-            yval = im->yorigin - pixie * (log10(value) - log10(im->minval));
+            yval = im->yorigin - im->y_pixie * (log10(value) - log10(im->minval));
         }
     }
     return yval;
index 180e08f10aacccd3b303b0a2ee3987aa2b74930c..ad57ffdd0b47b7ff7ab820b95164b20f15d339ae 100644 (file)
@@ -352,6 +352,8 @@ typedef struct image_desc_t {
     GHashTable* rrd_map;  /* a map of all rrd files in use for gdef entries */
     mutex_t *fontmap_mutex; /* Mutex for locking the global fontmap */
     enum image_init_en init_mode; /* do we need Cairo/Pango? */
+    double x_pixie; /* scale for X (see xtr() for reference) */
+    double y_pixie; /* scale for Y (see ytr() for reference) */
 } image_desc_t;
 
 /* Prototypes */