]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
md5: fix strict aliasing warnings
authorMike Frysinger <vapier@gentoo.org>
Wed, 10 Oct 2012 04:22:38 +0000 (00:22 -0400)
committerKarel Zak <kzak@redhat.com>
Wed, 10 Oct 2012 09:23:24 +0000 (11:23 +0200)
This is the same fix as was merged in gcc/binutils where this code
appears to originate from.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
lib/md5.c

index 26ec4bbd8d44bf6a200b69ca821c651605dd5ecf..488d16ef69b46926d45bb5fed4f46a4ae9b75cd1 100644 (file)
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -138,9 +138,12 @@ void MD5Final(unsigned char digest[MD5LENGTH], struct MD5Context *ctx)
     }
     byteReverse(ctx->in, 14);
 
-    /* Append length in bits and transform */
-    ((uint32_t *) ctx->in)[14] = ctx->bits[0];
-    ((uint32_t *) ctx->in)[15] = ctx->bits[1];
+    /* Append length in bits and transform.
+     * Use memcpy to avoid aliasing problems.  On most systems,
+     * this will be optimized away to the same code.
+     */
+    memcpy(&ctx->in[14 * sizeof(uint32_t)], &ctx->bits[0], 4);
+    memcpy(&ctx->in[15 * sizeof(uint32_t)], &ctx->bits[1], 4);
 
     MD5Transform(ctx->buf, (uint32_t *) ctx->in);
     byteReverse((unsigned char *) ctx->buf, 4);