View Issue Details [ Jump to Notes ] | [ Print ] | ||||||||
ID | Project | Category | View Status | Date Submitted | Last Update | ||||
0014314 | CMake | CMake | public | 2013-07-25 12:17 | 2013-12-02 08:51 | ||||
Reporter | Petr Machata | ||||||||
Assigned To | Brad King | ||||||||
Priority | normal | Severity | minor | Reproducibility | always | ||||
Status | closed | Resolution | fixed | ||||||
Platform | GCC | OS | Any | OS Version | |||||
Product Version | CMake 2.8.11.2 | ||||||||
Target Version | CMake 2.8.12 | Fixed in Version | CMake 2.8.12 | ||||||
Summary | 0014314: GCC warns about strict aliasing in cm_sha2.c | ||||||||
Description | When compiling cm_sha2.c, GCC gives the following warning: /builddir/build/BUILD/cmake-2.8.11.2/Source/cm_sha2.c: In function 'cmSHA1_Final': /builddir/build/BUILD/cmake-2.8.11.2/Source/cm_sha2.c:743:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] *(sha_word64*)&context->s1.buffer[56] = context->s1.bitcount; ^ There are four cases total. | ||||||||
Steps To Reproduce | 1) Compile with recent GCC (4.8?) 2) Inspect compile log | ||||||||
Additional Information | I propose fixing this by copying the necessary bytes through union. This should lead to the same binary, but will make it clear to GCC that we are only using the buffer as a bunch of characters. The test suite passes after applying the patch, that I attach. | ||||||||
Tags | No tags attached. | ||||||||
Attached Files | cmake-2.8.11-strict_aliasing.patch [^] (1,947 bytes) 2013-07-25 12:17 [Show Content]
cmake-strict_aliasing.patch [^] (648 bytes) 2013-07-25 12:42 [Show Content] | ||||||||
Relationships | |
Relationships |
Notes | |
(0033610) Petr Machata (reporter) 2013-07-25 12:42 |
Alternatively, you can pass -fno-strict-aliasing for that file when compiling with GCC. |
(0033611) Brad King (manager) 2013-07-25 13:13 |
Why not just use memcpy directly? It converts through pointer-to-void.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); |
(0033613) Petr Machata (reporter) 2013-07-25 14:06 |
Yes, I think you can. I don't see why it wouldn't work. |
(0033614) Brad King (manager) 2013-07-25 14:35 |
Thanks, patch applied: http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6a365d09 [^] |
(0034658) Robert Maynard (manager) 2013-12-02 08:51 |
Closing resolved issues that have not been updated in more than 4 months. |
Notes |
Issue History | |||
Date Modified | Username | Field | Change |
2013-07-25 12:17 | Petr Machata | New Issue | |
2013-07-25 12:17 | Petr Machata | File Added: cmake-2.8.11-strict_aliasing.patch | |
2013-07-25 12:42 | Petr Machata | Note Added: 0033610 | |
2013-07-25 12:42 | Petr Machata | File Added: cmake-strict_aliasing.patch | |
2013-07-25 13:13 | Brad King | Note Added: 0033611 | |
2013-07-25 14:06 | Petr Machata | Note Added: 0033613 | |
2013-07-25 14:35 | Brad King | Note Added: 0033614 | |
2013-07-25 14:35 | Brad King | Assigned To | => Brad King |
2013-07-25 14:35 | Brad King | Status | new => resolved |
2013-07-25 14:35 | Brad King | Resolution | open => fixed |
2013-07-25 14:35 | Brad King | Fixed in Version | => CMake 2.8.12 |
2013-07-25 14:35 | Brad King | Target Version | => CMake 2.8.12 |
2013-12-02 08:51 | Robert Maynard | Note Added: 0034658 | |
2013-12-02 08:51 | Robert Maynard | Status | resolved => closed |
Issue History |
Copyright © 2000 - 2018 MantisBT Team |