Code

write_kafka plugin: Use 32bit random number when formatting a random key.
authorFlorian Forster <octo@collectd.org>
Mon, 5 Dec 2016 10:52:35 +0000 (11:52 +0100)
committerFlorian Forster <octo@collectd.org>
Mon, 5 Dec 2016 10:52:37 +0000 (11:52 +0100)
Previously, negative numbers would be truncated to "ffffffff" by the
buffer length on architectures where longs are 64 bit.

Fixes: #2074
src/write_kafka.c

index dba09c03de4ea049437a0f3de33cd5a141c8ffc5..1712a478dbca635394f1b0f6de854adcd419979a 100644 (file)
@@ -31,6 +31,7 @@
 #include "utils_cmd_putval.h"
 #include "utils_format_graphite.h"
 #include "utils_format_json.h"
+#include "utils_random.h"
 
 #include <errno.h>
 #include <librdkafka/rdkafka.h>
@@ -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;
 }