diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2020-12-30 01:44:04 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2020-12-30 04:14:18 +0900 |
commit | 0b71a7e01d8d04a3668c349e2320c42c786f2382 (patch) | |
tree | 9df1fba5467b0d691922ee2c43b4ba63e71f94d4 /src/basic | |
parent | cd70fc373d21487473aa70f2f04c99fdc943a63f (diff) | |
download | systemd-0b71a7e01d8d04a3668c349e2320c42c786f2382.tar.gz |
siphash: introduce siphash24_compress_safe()
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/siphash24.h | 12 |
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); |