* [PATCH] md5: fix strict aliasing warnings
@ 2012-10-10 4:22 Mike Frysinger
2012-10-10 9:26 ` Karel Zak
0 siblings, 1 reply; 2+ messages in thread
From: Mike Frysinger @ 2012-10-10 4:22 UTC (permalink / raw)
To: util-linux-ng
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 | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/lib/md5.c b/lib/md5.c
index 26ec4bb..488d16e 100644
--- 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);
--
1.7.12
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] md5: fix strict aliasing warnings
2012-10-10 4:22 [PATCH] md5: fix strict aliasing warnings Mike Frysinger
@ 2012-10-10 9:26 ` Karel Zak
0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2012-10-10 9:26 UTC (permalink / raw)
To: Mike Frysinger; +Cc: util-linux-ng
On Wed, Oct 10, 2012 at 12:22:38AM -0400, Mike Frysinger wrote:
> lib/md5.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
Applied, thanks! My TODO list shorter now :-)
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-10-10 9:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-10 4:22 [PATCH] md5: fix strict aliasing warnings Mike Frysinger
2012-10-10 9:26 ` Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).