From 36e803d93a8a4fc0d9d3e234a375b94a4c879784 Mon Sep 17 00:00:00 2001 From: Elizabeth Myers Date: Fri, 18 Mar 2016 15:46:09 -0500 Subject: [PATCH] crypt: fix strict-aliasing warnings by using an explicit alias. --- librb/src/crypt.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/librb/src/crypt.c b/librb/src/crypt.c index 15c40a0b..206027fd 100644 --- a/librb/src/crypt.c +++ b/librb/src/crypt.c @@ -1350,7 +1350,7 @@ static void rb_sha256_init_ctx(struct sha256_ctx *ctx) static void *rb_sha256_finish_ctx(struct sha256_ctx *ctx, void *resbuf) { /* Take yet unprocessed bytes into account. */ - uint32_t bytes = ctx->buflen; + uint32_t bytes = ctx->buflen, *ptr; size_t pad; unsigned int i; @@ -1363,9 +1363,11 @@ static void *rb_sha256_finish_ctx(struct sha256_ctx *ctx, void *resbuf) memcpy(&ctx->buffer[bytes], SHA256_fillbuf, pad); /* Put the 64-bit file length in *bits* at the end of the buffer. */ - *(uint32_t *) & ctx->buffer[bytes + pad + 4] = SHA256_SWAP(ctx->total[0] << 3); - *(uint32_t *) & ctx->buffer[bytes + pad] = SHA256_SWAP((ctx->total[1] << 3) | - (ctx->total[0] >> 29)); + ptr = (uint32_t *)&ctx->buffer[bytes + pad + 4]; /* Avoid warnings about strict aliasing */ + *ptr = SHA256_SWAP(ctx->total[0] << 3); + + ptr = (uint32_t *)&ctx->buffer[bytes + pad]; + *ptr = SHA256_SWAP((ctx->total[1] << 3) | (ctx->total[0] >> 29)); /* Process last bytes. */ rb_sha256_process_block(ctx->buffer, bytes + pad + 8, ctx); @@ -1924,7 +1926,7 @@ static void rb_sha512_init_ctx(struct sha512_ctx *ctx) static void *rb_sha512_finish_ctx(struct sha512_ctx *ctx, void *resbuf) { /* Take yet unprocessed bytes into account. */ - uint64_t bytes = ctx->buflen; + uint64_t bytes = ctx->buflen, *ptr; size_t pad; unsigned int i; @@ -1937,9 +1939,11 @@ static void *rb_sha512_finish_ctx(struct sha512_ctx *ctx, void *resbuf) memcpy(&ctx->buffer[bytes], SHA512_fillbuf, pad); /* Put the 128-bit file length in *bits* at the end of the buffer. */ - *(uint64_t *) & ctx->buffer[bytes + pad + 8] = SHA512_SWAP(ctx->total[0] << 3); - *(uint64_t *) & ctx->buffer[bytes + pad] = SHA512_SWAP((ctx->total[1] << 3) | - (ctx->total[0] >> 61)); + ptr = (uint64_t *)&ctx->buffer[bytes + pad + 8]; /* Avoid warnings about strict aliasing */ + *ptr = SHA512_SWAP(ctx->total[0] << 3); + + ptr = (uint64_t *)&ctx->buffer[bytes + pad]; + *ptr = SHA512_SWAP((ctx->total[1] << 3) | (ctx->total[0] >> 61)); /* Process last bytes. */ rb_sha512_process_block(ctx->buffer, bytes + pad + 16, ctx);