summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ce41683)
raw | patch | inline | side by side (parent: ce41683)
author | Marc Fournier <marc.fournier@camptocamp.com> | |
Wed, 29 Apr 2015 22:15:19 +0000 (00:15 +0200) | ||
committer | Marc Fournier <marc.fournier@camptocamp.com> | |
Wed, 29 Apr 2015 22:15:19 +0000 (00:15 +0200) |
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).
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).
src/write_sensu.c | patch | blob | history |
diff --git a/src/write_sensu.c b/src/write_sensu.c
index 35db4f7b77ec009c7926674ef8b33c50d08593ca..cb0c2fe2dc4ce8cac97f7cb7fc7ef7f82bdb21a5 100644 (file)
--- a/src/write_sensu.c
+++ b/src/write_sensu.c
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;
+ }
}
}