From 9217571849eb99d1003e150e3165aedf06b07521 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 6 Jun 2013 12:36:30 +0300 Subject: [PATCH] var_expand*(): Fixed %N to work the same with little and big endian CPUs. Also use 64bit integer to do the MOD from, which should give somewhat better value distribution than with 32bit. --- src/lib/var-expand.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lib/var-expand.c b/src/lib/var-expand.c index 0e8ec6aa04..4eab9b666b 100644 --- a/src/lib/var-expand.c +++ b/src/lib/var-expand.c @@ -92,17 +92,21 @@ m_str_newhash(const char *str, struct var_expand_context *ctx) { string_t *hash = t_str_new(20); unsigned char result[MD5_RESULTLEN]; - unsigned int value; + unsigned int i; + uint64_t value; md5_get_digest(str, strlen(str), result); - memcpy(&value, result, sizeof(value)); + for (i = 0; i < sizeof(value); i++) { + value <<= 8; + value |= result[i]; + } if (ctx->width != 0) { value %= ctx->width; ctx->width = 0; } - str_printfa(hash, "%x", value); + str_printfa(hash, "%x", (unsigned int)value); while ((int)str_len(hash) < ctx->offset) str_insert(hash, 0, "0"); ctx->offset = 0; -- 2.47.3