md5/sha512: fix strict aliasing warnings
authorMike Frysinger <vapier@gentoo.org>
Wed, 19 Jun 2013 15:45:05 +0000 (11:45 -0400)
committerMike Frysinger <vapier@gentoo.org>
Wed, 19 Jun 2013 15:49:15 +0000 (11:49 -0400)
If the target can tolerate these issues, then gcc is smart enough
to generate the same code (x86_64 produces the same code).  If the
target can't, then it needs the memcpy anyways.

libbb/hash_md5_sha.c: In function 'common64_end':
libbb/hash_md5_sha.c:87:4: warning:
  dereferencing type-punned pointer will break strict-aliasing rules
    *(uint64_t *) (&ctx->wbuffer[64 - 8]) = t;
libbb/hash_md5_sha.c: In function 'sha512_end':
libbb/hash_md5_sha.c:886:4: warning:
  dereferencing type-punned pointer will break strict-aliasing rules
    *(uint64_t *) (&ctx->wbuffer[128 - 8]) = t;
libbb/hash_md5_sha.c:889:4: warning:
  dereferencing type-punned pointer will break strict-aliasing rules
    *(uint64_t *) (&ctx->wbuffer[128 - 16]) = t;

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

index b4d955e..e10cb39 100644 (file)
@@ -84,7 +84,7 @@ static void FAST_FUNC common64_end(md5_ctx_t *ctx, int swap_needed)
                        if (swap_needed)
                                t = bb_bswap_64(t);
                        /* wbuffer is suitably aligned for this */
-                       *(uint64_t *) (&ctx->wbuffer[64 - 8]) = t;
+                       memcpy(&ctx->wbuffer[64 - 8], &t, sizeof(t));
                }
                ctx->process_block(ctx);
                if (remaining >= 8)
@@ -883,10 +883,10 @@ void FAST_FUNC sha512_end(sha512_ctx_t *ctx, void *resbuf)
                        uint64_t t;
                        t = ctx->total64[0] << 3;
                        t = SWAP_BE64(t);
-                       *(uint64_t *) (&ctx->wbuffer[128 - 8]) = t;
+                       memcpy(&ctx->wbuffer[128 - 8], &t, sizeof(t));
                        t = (ctx->total64[1] << 3) | (ctx->total64[0] >> 61);
                        t = SWAP_BE64(t);
-                       *(uint64_t *) (&ctx->wbuffer[128 - 16]) = t;
+                       memcpy(&ctx->wbuffer[128 - 16], &t, sizeof(t));
                }
                sha512_process_block128(ctx);
                if (remaining >= 16)