summaryrefslogtreecommitdiffstats
path: root/test/dsets.c
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2011-08-12 15:12:13 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2011-08-12 15:12:13 (GMT)
commit4dbc3b0478a01302cd8f62cc914e99a36f4e8efd (patch)
tree8a7149588eb4e33b5e5bed56070d4155982fd275 /test/dsets.c
parent3a448c4f8565178cf218e138086d46bfa5f66e91 (diff)
downloadhdf5-4dbc3b0478a01302cd8f62cc914e99a36f4e8efd.zip
hdf5-4dbc3b0478a01302cd8f62cc914e99a36f4e8efd.tar.gz
hdf5-4dbc3b0478a01302cd8f62cc914e99a36f4e8efd.tar.bz2
[svn-r21221] 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. But I tested the same change for the trunk with h5committest.
Diffstat (limited to 'test/dsets.c')
-rw-r--r--test/dsets.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/test/dsets.c b/test/dsets.c
index 902048b..09256f4 100644
--- a/test/dsets.c
+++ b/test/dsets.c
@@ -3677,7 +3677,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]);