summaryrefslogtreecommitdiffstats
path: root/Source/cm_sha2.c
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2013-07-25 17:03:31 (GMT)
committerBrad King <brad.king@kitware.com>2013-07-25 17:10:13 (GMT)
commit6a365d090193bb7cd5249015b8dea7d0b9449b87 (patch)
tree5bc44d5d87904c4cd0c217a22739b42e85c91e1d /Source/cm_sha2.c
parent10e54cd6c9437c27b3a758f8de1455086c53fae5 (diff)
downloadCMake-6a365d090193bb7cd5249015b8dea7d0b9449b87.zip
CMake-6a365d090193bb7cd5249015b8dea7d0b9449b87.tar.gz
CMake-6a365d090193bb7cd5249015b8dea7d0b9449b87.tar.bz2
sha2: Avoid type-punned pointer dereference (#14314)
GCC warns: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] on constructs like *(sha_word64*)&var = so use memcpy to perform such assignments instead.
Diffstat (limited to 'Source/cm_sha2.c')
-rw-r--r--Source/cm_sha2.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/Source/cm_sha2.c b/Source/cm_sha2.c
index 12c39ed..24de2b2 100644
--- a/Source/cm_sha2.c
+++ b/Source/cm_sha2.c
@@ -740,7 +740,8 @@ void SHA1_Final(sha_byte digest[], SHA_CTX* context) {
/* Convert FROM host byte order */
REVERSE64(context->s1.bitcount,context->s1.bitcount);
#endif
- *(sha_word64*)&context->s1.buffer[56] = context->s1.bitcount;
+ MEMCPY_BCOPY(&context->s1.buffer[56], &context->s1.bitcount,
+ sizeof(sha_word64));
/* Final transform: */
SHA1_Internal_Transform(context, (sha_word32*)context->s1.buffer);
@@ -1067,7 +1068,8 @@ void SHA256_Internal_Last(SHA_CTX* context) {
*context->s256.buffer = 0x80;
}
/* Set the bit count: */
- *(sha_word64*)&context->s256.buffer[56] = context->s256.bitcount;
+ MEMCPY_BCOPY(&context->s256.buffer[56], &context->s256.bitcount,
+ sizeof(sha_word64));
/* Final transform: */
SHA256_Internal_Transform(context, (sha_word32*)context->s256.buffer);
@@ -1475,8 +1477,10 @@ void SHA512_Internal_Last(SHA_CTX* context) {
*context->s512.buffer = 0x80;
}
/* Store the length of input data (in bits): */
- *(sha_word64*)&context->s512.buffer[112] = context->s512.bitcount[1];
- *(sha_word64*)&context->s512.buffer[120] = context->s512.bitcount[0];
+ MEMCPY_BCOPY(&context->s512.buffer[112], &context->s512.bitcount[1],
+ sizeof(sha_word64));
+ MEMCPY_BCOPY(&context->s512.buffer[120], &context->s512.bitcount[0],
+ sizeof(sha_word64));
/* Final transform: */
SHA512_Internal_Transform(context, (sha_word64*)context->s512.buffer);