From: Florian Forster Date: Sun, 27 Nov 2016 13:58:42 +0000 (+0100) Subject: src/utils_latency_config.c: Avoid nested compound literals. X-Git-Tag: collectd-5.7.0~14 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2d57032f3b7f923baf06b20325957c3e3f1a9f0b;p=collectd.git src/utils_latency_config.c: Avoid nested compound literals. So GCC 4.6 doesn't crash. --- diff --git a/src/daemon/utils_time.h b/src/daemon/utils_time.h index 2d83e0bb..db510afe 100644 --- a/src/daemon/utils_time.h +++ b/src/daemon/utils_time.h @@ -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) { \ diff --git a/src/utils_latency_config.c b/src/utils_latency_config.c index 36c78ebe..133678e5 100644 --- a/src/utils_latency_config.c +++ b/src/utils_latency_config.c @@ -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); diff --git a/src/utils_latency_test.c b/src/utils_latency_test.c index 3505ca3e..01f194f1 100644 --- a/src/utils_latency_test.c +++ b/src/utils_latency_test.c @@ -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, }, };