summaryrefslogtreecommitdiffstats
path: root/src/basic
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2020-12-29 17:44:04 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2020-12-29 20:14:18 +0100
commit0b71a7e01d8d04a3668c349e2320c42c786f2382 (patch)
tree9df1fba5467b0d691922ee2c43b4ba63e71f94d4 /src/basic
parentresolve: do not compare key twice (diff)
downloadsystemd-0b71a7e01d8d04a3668c349e2320c42c786f2382.tar.xz
systemd-0b71a7e01d8d04a3668c349e2320c42c786f2382.zip
siphash: introduce siphash24_compress_safe()
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/siphash24.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/basic/siphash24.h b/src/basic/siphash24.h
index 90a6de00e4..0b3e845bf4 100644
--- a/src/basic/siphash24.h
+++ b/src/basic/siphash24.h
@@ -5,9 +5,9 @@
#include <inttypes.h>
#include <stddef.h>
#include <stdint.h>
-#include <string.h>
#include <sys/types.h>
+#include "string-util.h"
#include "time-util.h"
struct siphash {
@@ -33,11 +33,15 @@ static inline void siphash24_compress_usec_t(usec_t in, struct siphash *state) {
siphash24_compress(&in, sizeof in, state);
}
-static inline void siphash24_compress_string(const char *in, struct siphash *state) {
- if (!in)
+static inline void siphash24_compress_safe(const void *in, size_t inlen, struct siphash *state) {
+ if (inlen == 0)
return;
- siphash24_compress(in, strlen(in), state);
+ siphash24_compress(in, inlen, state);
+}
+
+static inline void siphash24_compress_string(const char *in, struct siphash *state) {
+ siphash24_compress_safe(in, strlen_ptr(in), state);
}
uint64_t siphash24_finalize(struct siphash *state);