diff options
author | Mike Frysinger | 2012-10-10 06:22:38 +0200 |
---|---|---|
committer | Karel Zak | 2012-10-10 11:23:24 +0200 |
commit | 6c6f7196880bdb4f48742b3df4457feca9c332d0 (patch) | |
tree | 0f24a168649ada1dcfdad1126e3f39899e2b239e /lib | |
parent | tests: fix mount move test to work with shared mount (diff) | |
download | kernel-qcow2-util-linux-6c6f7196880bdb4f48742b3df4457feca9c332d0.tar.gz kernel-qcow2-util-linux-6c6f7196880bdb4f48742b3df4457feca9c332d0.tar.xz kernel-qcow2-util-linux-6c6f7196880bdb4f48742b3df4457feca9c332d0.zip |
md5: fix strict aliasing warnings
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>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/md5.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -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); |