Mercurial > dovecot > core-2.2
changeset 16473:956324a5fc86
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.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 06 Jun 2013 12:36:30 +0300 |
parents | 8f192f64fd98 |
children | 561f36451dc2 |
files | src/lib/var-expand.c |
diffstat | 1 files changed, 7 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/var-expand.c Thu Jun 06 12:24:27 2013 +0300 +++ b/src/lib/var-expand.c Thu Jun 06 12:36:30 2013 +0300 @@ -92,17 +92,21 @@ { 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;