summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2011-08-12 14:38:30 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2011-08-12 14:38:30 (GMT)
commitf32d49916d41592a790219e0869a3dbc5e1b49f3 (patch)
tree4832dc99c516a8ef11329bc8973f0bae8dffd2a0
parent14f8f4d4370a70afc4c354d0d4b2c6358fa4acf4 (diff)
downloadhdf5-f32d49916d41592a790219e0869a3dbc5e1b49f3.zip
hdf5-f32d49916d41592a790219e0869a3dbc5e1b49f3.tar.gz
hdf5-f32d49916d41592a790219e0869a3dbc5e1b49f3.tar.bz2
[svn-r21220] The original code
i_mask = ~((unsigned)~0 << (precision[0] + offset[0])) & ((unsigned)~0 << offset[0]); in line 3680 left shifted a 32-bit integer for 32-bit. The result is undefined by C language. A user discovered it using clang compiler with -fcatch-undefined-behavior option (see Issue 7674 in Jira). So I changed it in a funny way to avoid it. Tested on jam, koala, and heiwa.
-rw-r--r--test/dsets.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/test/dsets.c b/test/dsets.c
index 0c62736..959ac43 100644
--- a/test/dsets.c
+++ b/test/dsets.c
@@ -3664,7 +3664,18 @@ test_nbit_compound_2(hid_t file)
/* Check that the values read are the same as the values written
* Use mask for checking the significant bits, ignoring the padding bits
*/
- i_mask = ~((unsigned)~0 << (precision[0] + offset[0])) & ((unsigned)~0 << offset[0]);
+ /* The original code
+ * i_mask = ~((unsigned)~0 << (precision[0] + offset[0])) & ((unsigned)~0 << offset[0]);
+ * left shift a 32-bit integer for 32-bit. The result is undefined by C language. A user
+ * discovered it using clang compiler with -fcatch-undefined-behavior option (see Issue 7674
+ * in Jira). So I changed it in a funny way as below to avoid it. SLU - 2011/8/11
+ */
+ if(sizeof(unsigned) > 4)
+ i_mask = ~((unsigned)~0 << (precision[0] + offset[0])) & ((unsigned)~0 << offset[0]);
+ else {
+ i_mask = 0xffffffff;
+ i_mask = i_mask & ((unsigned)~0 << offset[0]);
+ }
c_mask = ~((unsigned)~0 << (precision[1] + offset[1])) & ((unsigned)~0 << offset[1]);
s_mask = ~((unsigned)~0 << (precision[2] + offset[2])) & ((unsigned)~0 << offset[2]);
b_mask = ~((unsigned)~0 << (precision[4] + offset[4])) & ((unsigned)~0 << offset[4]);