src/utils_latency_config.c: Avoid nested compound literals.
authorFlorian Forster <octo@collectd.org>
Sun, 27 Nov 2016 13:58:42 +0000 (14:58 +0100)
committerFlorian Forster <octo@collectd.org>
Sun, 27 Nov 2016 15:58:01 +0000 (16:58 +0100)
So GCC 4.6 doesn't crash.

src/daemon/utils_time.h
src/utils_latency_config.c
src/utils_latency_test.c

index 2d83e0b..db510af 100644 (file)
@@ -88,8 +88,9 @@ extern cdtime_t cdtime_mock;
 
 #define CDTIME_T_TO_DOUBLE(t)                                                  \
   (double) { ((double)(t)) / 1073741824.0 }
+#define DOUBLE_TO_CDTIME_T_STATIC(d) ((cdtime_t)((d)*1073741824.0))
 #define DOUBLE_TO_CDTIME_T(d)                                                  \
-  (cdtime_t) { (cdtime_t)((d)*1073741824.0) }
+  (cdtime_t) { DOUBLE_TO_CDTIME_T_STATIC(d) }
 
 #define CDTIME_T_TO_TIMEVAL(t)                                                 \
   (struct timeval) {                                                           \
index 36c78eb..133678e 100644 (file)
@@ -85,10 +85,10 @@ static int latency_config_add_bucket(latency_config_t *conf, oconfig_item_t *ci,
     return ENOMEM;
   }
   conf->buckets = tmp;
-  conf->buckets[conf->buckets_num] = (latency_bucket_t){
-      .lower_bound = DOUBLE_TO_CDTIME_T(ci->values[0].value.number),
-      .upper_bound = DOUBLE_TO_CDTIME_T(ci->values[1].value.number),
-  };
+  conf->buckets[conf->buckets_num].lower_bound =
+      DOUBLE_TO_CDTIME_T(ci->values[0].value.number);
+  conf->buckets[conf->buckets_num].upper_bound =
+      DOUBLE_TO_CDTIME_T(ci->values[1].value.number);
   conf->buckets_num++;
 
   return (0);
index 3505ca3..01f194f 100644 (file)
@@ -153,63 +153,63 @@ DEF_TEST (get_rate) {
     double want;
   } cases[] = {
     { // bucket 6 is zero
-      DOUBLE_TO_CDTIME_T(0.750),
-      DOUBLE_TO_CDTIME_T(0.875),
+      DOUBLE_TO_CDTIME_T_STATIC(0.750),
+      DOUBLE_TO_CDTIME_T_STATIC(0.875),
       0.00,
     },
     { // bucket 7 contains the t=1 update
-      DOUBLE_TO_CDTIME_T(0.875),
-      DOUBLE_TO_CDTIME_T(1.000),
+      DOUBLE_TO_CDTIME_T_STATIC(0.875),
+      DOUBLE_TO_CDTIME_T_STATIC(1.000),
       1.00,
     },
     { // range: bucket 7 - bucket 15; contains the t=1 and t=2 updates
-      DOUBLE_TO_CDTIME_T(0.875),
-      DOUBLE_TO_CDTIME_T(2.000),
+      DOUBLE_TO_CDTIME_T_STATIC(0.875),
+      DOUBLE_TO_CDTIME_T_STATIC(2.000),
       2.00,
     },
     { // lower bucket is only partially applied
-      DOUBLE_TO_CDTIME_T(0.875 + (0.125 / 4)),
-      DOUBLE_TO_CDTIME_T(2.000),
+      DOUBLE_TO_CDTIME_T_STATIC(0.875 + (0.125 / 4)),
+      DOUBLE_TO_CDTIME_T_STATIC(2.000),
       1.75,
     },
     { // upper bucket is only partially applied
-      DOUBLE_TO_CDTIME_T(0.875),
-      DOUBLE_TO_CDTIME_T(2.000 - (0.125 / 4)),
+      DOUBLE_TO_CDTIME_T_STATIC(0.875),
+      DOUBLE_TO_CDTIME_T_STATIC(2.000 - (0.125 / 4)),
       1.75,
     },
     { // both buckets are only partially applied
-      DOUBLE_TO_CDTIME_T(0.875 + (0.125 / 4)),
-      DOUBLE_TO_CDTIME_T(2.000 - (0.125 / 4)),
+      DOUBLE_TO_CDTIME_T_STATIC(0.875 + (0.125 / 4)),
+      DOUBLE_TO_CDTIME_T_STATIC(2.000 - (0.125 / 4)),
       1.50,
     },
     { // lower bound is unspecified
       0,
-      DOUBLE_TO_CDTIME_T(2.000),
+      DOUBLE_TO_CDTIME_T_STATIC(2.000),
       2.00,
     },
     { // upper bound is unspecified
-      DOUBLE_TO_CDTIME_T(125.000 - 0.125),
+      DOUBLE_TO_CDTIME_T_STATIC(125.000 - 0.125),
       0,
       1.00,
     },
     { // overflow test: upper >> longest latency
-      DOUBLE_TO_CDTIME_T(1.000),
-      DOUBLE_TO_CDTIME_T(999999),
+      DOUBLE_TO_CDTIME_T_STATIC(1.000),
+      DOUBLE_TO_CDTIME_T_STATIC(999999),
       124.00,
     },
     { // overflow test: lower > longest latency
-      DOUBLE_TO_CDTIME_T(130),
+      DOUBLE_TO_CDTIME_T_STATIC(130),
       0,
       0.00,
     },
     { // lower > upper => error
-      DOUBLE_TO_CDTIME_T(10),
-      DOUBLE_TO_CDTIME_T(9),
+      DOUBLE_TO_CDTIME_T_STATIC(10),
+      DOUBLE_TO_CDTIME_T_STATIC(9),
       NAN,
     },
     { // lower == upper => zero
-      DOUBLE_TO_CDTIME_T(9),
-      DOUBLE_TO_CDTIME_T(9),
+      DOUBLE_TO_CDTIME_T_STATIC(9),
+      DOUBLE_TO_CDTIME_T_STATIC(9),
       0.00,
     },
   };