From: Marc Fournier Date: Wed, 29 Apr 2015 22:15:19 +0000 (+0200) Subject: write_sensu: fix format-string portability problem X-Git-Tag: collectd-5.5.0~31^2 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=4c385259da89a7d9b9f3fff23faa4b03a528252d;p=collectd.git write_sensu: fix format-string portability problem Casting counters, derives and abolutes to int64_t was incorrect, as they are respectively `unsigned long long`, `int64_t` and `uint64_t`. Apart from potentially loosing precision, the `%ld` format-string made clang choke on the 32bit architecture (follow-up to 78340212). --- diff --git a/src/write_sensu.c b/src/write_sensu.c index 35db4f7b..cb0c2fe2 100644 --- a/src/write_sensu.c +++ b/src/write_sensu.c @@ -484,18 +484,29 @@ static char *sensu_value_to_json(struct sensu_host const *host, /* {{{ */ return NULL; } } else { - int64_t tmp_v; - if (ds->ds[index].type == DS_TYPE_DERIVE) - tmp_v = (int64_t) vl->values[index].derive; - else if (ds->ds[index].type == DS_TYPE_ABSOLUTE) - tmp_v = (int64_t) vl->values[index].absolute; - else - tmp_v = (int64_t) vl->values[index].counter; - res = asprintf(&value_str, "%ld", tmp_v); - if (res == -1) { - free(ret_str); - ERROR("write_sensu plugin: Unable to alloc memory"); - return NULL; + if (ds->ds[index].type == DS_TYPE_DERIVE) { + res = asprintf(&value_str, "%"PRIi64, vl->values[index].derive); + if (res == -1) { + free(ret_str); + ERROR("write_sensu plugin: Unable to alloc memory"); + return NULL; + } + } + else if (ds->ds[index].type == DS_TYPE_ABSOLUTE) { + res = asprintf(&value_str, "%"PRIu64, vl->values[index].absolute); + if (res == -1) { + free(ret_str); + ERROR("write_sensu plugin: Unable to alloc memory"); + return NULL; + } + } + else { + res = asprintf(&value_str, "%llu", vl->values[index].counter); + if (res == -1) { + free(ret_str); + ERROR("write_sensu plugin: Unable to alloc memory"); + return NULL; + } } }