summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2011-08-31 20:28:03 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2011-08-31 20:28:03 (GMT)
commite3b66f853aeafe2260117c23f1d56746738289e4 (patch)
tree9e11ffb3bf9f520bbf336ea3743d93610a00ece0 /test
parent3852fe2e1047d0c42ed626c296746f1be9f76283 (diff)
downloadhdf5-e3b66f853aeafe2260117c23f1d56746738289e4.zip
hdf5-e3b66f853aeafe2260117c23f1d56746738289e4.tar.gz
hdf5-e3b66f853aeafe2260117c23f1d56746738289e4.tar.bz2
[svn-r21343] Issue 7674 - clang compiler with -fcatch-undefined-behavior -ftrapv discovered several problems in the test suite. One of
them is in the INIT_INTEGER macro definition in dt_arith.c. It complained about line 150 where it tried to subtract 1 from the negative minimal value of "int", causing it to overflow (or underflow). So I revised the code to avoid it. Tested on jam and Mac OS Lion with CLANG compiler. But I tested the same change for the trunk with h5committest.
Diffstat (limited to 'test')
-rw-r--r--test/dt_arith.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/test/dt_arith.c b/test/dt_arith.c
index 3a673fb..7948c65 100644
--- a/test/dt_arith.c
+++ b/test/dt_arith.c
@@ -121,7 +121,7 @@ static int without_hardware_g = 0;
TYPE value2 = 0; \
\
/* Allocate buffers */ \
- NELMTS=(SRC_PREC-1)*3+1; \
+ NELMTS=SRC_PREC*3; \
BUF = (unsigned char*)aligned_malloc(NELMTS*MAX(SRC_SIZE, DST_SIZE)); \
SAVED = (unsigned char*)aligned_malloc(NELMTS*MAX(SRC_SIZE, DST_SIZE)); \
HDmemset(BUF, 0, NELMTS*MAX(SRC_SIZE, DST_SIZE)); \
@@ -132,7 +132,7 @@ static int without_hardware_g = 0;
\
/*positive values, ascending order. VALUE1 starts from 00000001, to 00000010, until 10000000*/ \
/*VALUE2 ascends from 00000000, to 00000011, 00000111,..., until 11111111.*/ \
- for(n=0; n<SRC_PREC-1; n++) { \
+ for(n=0; n<SRC_PREC; n++) { \
if(value1<=SRC_MAX && value1>=SRC_MIN) { \
memcpy(buf_p, &value1, SRC_SIZE); \
memcpy(saved_p, &value1, SRC_SIZE); \
@@ -146,20 +146,26 @@ static int without_hardware_g = 0;
saved_p += SRC_SIZE; \
} \
\
- value1 <<= 1; \
- value2 = (value1 - 1) | value1; \
+ if(n<SRC_PREC-2) { \
+ value1 <<= 1; \
+ value2 = (value1 - 1) | value1; \
+ } else if(n==SRC_PREC-2) { /*to avoid overflow of negative values for signed integer*/ \
+ value1 <<= 1; \
+ value2 = (~value1) | value1; \
+ } \
} \
\
/* negative values for signed; descending positive values for unsigned */ \
/* VALUE2 descends from 11111111 to 11111110, 11111100, ..., until 10000000. */ \
- for(n=0; n<SRC_PREC; n++) { \
+ for(n=0; n<SRC_PREC-1; n++) { \
if(value2<=SRC_MAX && value2>=SRC_MIN) { \
memcpy(buf_p, &value2, SRC_SIZE); \
memcpy(saved_p, &value2, SRC_SIZE); \
buf_p += SRC_SIZE; \
saved_p += SRC_SIZE; \
} \
- value2 <<= 1; \
+ if(n<SRC_PREC-1) \
+ value2 <<= 1; \
} \
}