From: Florian Forster Date: Mon, 5 Dec 2016 10:52:35 +0000 (+0100) Subject: write_kafka plugin: Use 32bit random number when formatting a random key. X-Git-Tag: collectd-5.7.0~2^2~1 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=11011dc93691989513ff2101c221ea15dab5658a;p=collectd.git write_kafka plugin: Use 32bit random number when formatting a random key. Previously, negative numbers would be truncated to "ffffffff" by the buffer length on architectures where longs are 64 bit. Fixes: #2074 --- diff --git a/src/write_kafka.c b/src/write_kafka.c index dba09c03..1712a478 100644 --- a/src/write_kafka.c +++ b/src/write_kafka.c @@ -31,6 +31,7 @@ #include "utils_cmd_putval.h" #include "utils_format_graphite.h" #include "utils_format_json.h" +#include "utils_random.h" #include #include @@ -88,7 +89,7 @@ static uint32_t kafka_hash(const char *keydata, size_t keylen) { #define KAFKA_RANDOM_KEY_BUFFER \ (char[KAFKA_RANDOM_KEY_SIZE]) { "" } static char *kafka_random_key(char buffer[static KAFKA_RANDOM_KEY_SIZE]) { - ssnprintf(buffer, KAFKA_RANDOM_KEY_SIZE, "%08lX", (unsigned long)mrand48()); + ssnprintf(buffer, KAFKA_RANDOM_KEY_SIZE, "%08" PRIX32, cdrand_u()); return buffer; }