]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
var_expand*(): Fixed %N to work the same with little and big endian CPUs.
authorTimo Sirainen <tss@iki.fi>
Thu, 6 Jun 2013 09:36:30 +0000 (12:36 +0300)
committerTimo Sirainen <tss@iki.fi>
Thu, 6 Jun 2013 09:36:30 +0000 (12:36 +0300)
Also use 64bit integer to do the MOD from, which should give somewhat better
value distribution than with 32bit.

src/lib/var-expand.c

index 0e8ec6aa049363a158cfa5bee314a5497d93ff8d..4eab9b666bb5297e864f9ece2a332f901271e157 100644 (file)
@@ -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;