From cfccbfa8590dffe9a1282dba6ce757f686f55599 Mon Sep 17 00:00:00 2001 From: Mikko Lehto Date: Tue, 17 May 2016 14:49:54 +0300 Subject: [PATCH] lib/srutils: fix gcc warning GH#612 > sha256.c: In function 'sr_SHA256_Final': > sha256.c:613:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] > *(sha2_word64*)&context->buffer[SHA256_SHORT_BLOCK_LENGTH] = context->bitcount; > ^ > sha256.c: In function 'SHA512_Last': > sha256.c:930:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] > *(sha2_word64*)&context->buffer[SHA512_SHORT_BLOCK_LENGTH] = context->bitcount[1]; > ^ > sha256.c:931:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] > *(sha2_word64*)&context->buffer[SHA512_SHORT_BLOCK_LENGTH+8] = context->bitcount[0]; > ^ --- lib/srutils/sha256.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/srutils/sha256.c b/lib/srutils/sha256.c index 90efd157f48..2b405511af9 100644 --- a/lib/srutils/sha256.c +++ b/lib/srutils/sha256.c @@ -610,7 +610,7 @@ void sr_SHA256_Final(sha2_byte digest[], SHA256_CTX* context) { *context->buffer = 0x80; } /* Set the bit count: */ - *(sha2_word64*)&context->buffer[SHA256_SHORT_BLOCK_LENGTH] = context->bitcount; + MEMCPY_BCOPY(&(context->buffer[SHA256_SHORT_BLOCK_LENGTH]), &(context->bitcount), sizeof(sha2_word64)); /* Final transform: */ SHA256_Transform(context, (sha2_word32*)context->buffer); @@ -927,8 +927,8 @@ void SHA512_Last(SHA512_CTX* context) { *context->buffer = 0x80; } /* Store the length of input data (in bits): */ - *(sha2_word64*)&context->buffer[SHA512_SHORT_BLOCK_LENGTH] = context->bitcount[1]; - *(sha2_word64*)&context->buffer[SHA512_SHORT_BLOCK_LENGTH+8] = context->bitcount[0]; + MEMCPY_BCOPY(&(context->buffer[SHA512_SHORT_BLOCK_LENGTH+0]), &(context->bitcount[1]), sizeof(sha2_word64)); + MEMCPY_BCOPY(&(context->buffer[SHA512_SHORT_BLOCK_LENGTH+8]), &(context->bitcount[0]), sizeof(sha2_word64)); /* Final transform: */ SHA512_Transform(context, (sha2_word64*)context->buffer);