Replace all occurrences of `strcpy' with `sstrncpy'.
[collectd.git] / src / rrdtool.c
index dc06d68..adf6eeb 100644 (file)
@@ -285,7 +285,7 @@ static int ds_get (char ***ret, const data_set_t *ds, const value_list_t *vl)
 
                if (isnan (d->min))
                {
-                       strcpy (min, "U");
+                       sstrncpy (min, "U", sizeof (min));
                }
                else
                {
@@ -295,7 +295,7 @@ static int ds_get (char ***ret, const data_set_t *ds, const value_list_t *vl)
 
                if (isnan (d->max))
                {
-                       strcpy (max, "U");
+                       sstrncpy (max, "U", sizeof (max));
                }
                else
                {
@@ -893,6 +893,19 @@ static int rrd_cache_insert (const char *filename,
        return (0);
 } /* int rrd_cache_insert */
 
+static int rrd_compare_numeric (const void *a_ptr, const void *b_ptr)
+{
+       int a = *((int *) a_ptr);
+       int b = *((int *) b_ptr);
+
+       if (a < b)
+               return (-1);
+       else if (a > b)
+               return (1);
+       else
+               return (0);
+} /* int rrd_compare_numeric */
+
 static int rrd_write (const data_set_t *ds, const value_list_t *vl)
 {
        struct stat  statbuf;
@@ -1031,6 +1044,12 @@ static int rrd_config (const char *key, const char *value)
                        if (rra_timespans_custom[rra_timespans_custom_num] != 0)
                                rra_timespans_custom_num++;
                } /* while (strtok_r) */
+
+               qsort (/* base = */ rra_timespans_custom,
+                               /* nmemb  = */ rra_timespans_custom_num,
+                               /* size   = */ sizeof (rra_timespans_custom[0]),
+                               /* compar = */ rrd_compare_numeric);
+
                free (value_copy);
        }
        else if (strcasecmp ("XFF", key) == 0)
@@ -1080,12 +1099,7 @@ static int rrd_init (void)
        if (stepsize < 0)
                stepsize = 0;
        if (heartbeat <= 0)
-       {
-               if (stepsize > 0)
-                       heartbeat = 2 * stepsize;
-               else
-                       heartbeat = 0;
-       }
+               heartbeat = 2 * stepsize;
 
        if ((heartbeat > 0) && (heartbeat < interval_g))
                WARNING ("rrdtool plugin: Your `heartbeat' is "