diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2009-04-23 18:25:16 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2009-04-23 18:25:16 (GMT) |
commit | f098d20ab95c885414f82ee310b3692929e76227 (patch) | |
tree | 8f9eaca942902a988ccc12e983144d6b3d0b04c4 /src/H5private.h | |
parent | b1f8b21130a4f95d2dcd4b9343ed05e93c33f35c (diff) | |
download | hdf5-f098d20ab95c885414f82ee310b3692929e76227.zip hdf5-f098d20ab95c885414f82ee310b3692929e76227.tar.gz hdf5-f098d20ab95c885414f82ee310b3692929e76227.tar.bz2 |
[svn-r16847] Description:
Bring r16846 from revise_chunks branch back to trunk:
Fix broken (for how long?) H5_ASSIGN_OVERFLOW macro to actually detect
overflows during assignments, along with several errors it [now] detected.
Cleaned up a fix minor warnings and/or pieces of code also.
Tested on:
FreeBSD/32 6.3 (duty) in debug mode
(h5committest not needed - multi-platform test performed on branch)
Diffstat (limited to 'src/H5private.h')
-rw-r--r-- | src/H5private.h | 106 |
1 files changed, 77 insertions, 29 deletions
diff --git a/src/H5private.h b/src/H5private.h index d392548..7a7ec53 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -439,35 +439,6 @@ #endif /* - * A macro for detecting over/under-flow when casting between types - */ -#ifndef NDEBUG -#define H5_CHECK_OVERFLOW(var, vartype, casttype) \ -{ \ - casttype _tmp_overflow = (casttype)(var); \ - assert((var) == (vartype)_tmp_overflow); \ -} -#else /* NDEBUG */ -#define H5_CHECK_OVERFLOW(var, vartype, casttype) -#endif /* NDEBUG */ - -/* - * A macro for detecting over/under-flow when assigning between types - */ -#ifndef NDEBUG -#define H5_ASSIGN_OVERFLOW(dst, src, srctype, dsttype) \ -{ \ - srctype _tmp_overflow = (srctype)(src); \ - dsttype _tmp_overflow2 = (dsttype)(_tmp_overflow); \ - assert((dsttype)_tmp_overflow == _tmp_overflow2); \ - (dst) = _tmp_overflow2; \ -} -#else /* NDEBUG */ -#define H5_ASSIGN_OVERFLOW(dst, src, srctype, dsttype) \ - (dst) = (dsttype)(src); -#endif /* NDEBUG */ - -/* * Data types and functions for timing certain parts of the library. */ typedef struct { @@ -764,6 +735,7 @@ H5_DLL int HDfprintf (FILE *stream, const char *fmt, ...); #endif /* HDstat */ typedef struct stat64 h5_stat_t; typedef off64_t h5_stat_size_t; + #define H5_SIZEOF_H5_STAT_SIZE_T H5_SIZEOF_OFF64_T #else /* H5_SIZEOF_OFF_T!=8 && ... */ #ifndef HDfstat #define HDfstat(F,B) fstat(F,B) @@ -773,6 +745,7 @@ H5_DLL int HDfprintf (FILE *stream, const char *fmt, ...); #endif /* HDstat */ typedef struct stat h5_stat_t; typedef off_t h5_stat_size_t; + #define H5_SIZEOF_H5_STAT_SIZE_T H5_SIZEOF_OFF_T #endif /* H5_SIZEOF_OFF_T!=8 && ... */ #endif /* !defined(HDfstat) || !defined(HDstat) */ @@ -1237,6 +1210,9 @@ H5_DLL int64_t HDstrtoll (const char *s, const char **rest, int base); #ifndef HDstrtoul #define HDstrtoul(S,R,N) strtoul(S,R,N) #endif /* HDstrtoul */ +#ifndef HDstrtoull + #define HDstrtoull(S,R,N) strtoull(S,R,N) +#endif /* HDstrtoul */ #ifndef HDstrxfrm #define HDstrxfrm(X,Y,Z) strxfrm(X,Y,Z) #endif /* HDstrxfrm */ @@ -1376,6 +1352,78 @@ extern char *strdup(const char *s); #define HDpthread_self_ulong() ((unsigned long)pthread_self()) #endif /* HDpthread_self_ulong */ +/* + * A macro for detecting over/under-flow when casting between types + */ +#ifndef NDEBUG +#define H5_CHECK_OVERFLOW(var, vartype, casttype) \ +{ \ + casttype _tmp_overflow = (casttype)(var); \ + assert((var) == (vartype)_tmp_overflow); \ +} +#else /* NDEBUG */ +#define H5_CHECK_OVERFLOW(var, vartype, casttype) +#endif /* NDEBUG */ + +/* + * A macro for detecting over/under-flow when assigning between types + */ +#ifndef NDEBUG +#define ASSIGN_TO_SMALLER_SIZE(dst, dsttype, src, srctype) \ +{ \ + srctype _tmp_src = (srctype)(src); \ + dsttype _tmp_dst = (dsttype)(_tmp_src); \ + assert(_tmp_src == (srctype)_tmp_dst); \ + (dst) = _tmp_dst; \ +} + +#define ASSIGN_TO_LARGER_SIZE_SAME_SIGNED(dst, dsttype, src, srctype) \ + (dst) = (dsttype)(src); + +#define ASSIGN_TO_LARGER_SIZE_SIGNED_TO_UNSIGNED(dst, dsttype, src, srctype) \ +{ \ + srctype _tmp_src = (srctype)(src); \ + dsttype _tmp_dst = (dsttype)(_tmp_src); \ + assert(_tmp_src >= 0); \ + assert(_tmp_src == _tmp_dst); \ + (dst) = _tmp_dst; \ +} + +#define ASSIGN_TO_LARGER_SIZE_UNSIGNED_TO_SIGNED(dst, dsttype, src, srctype) \ + (dst) = (dsttype)(src); + +#define ASSIGN_TO_SAME_SIZE_UNSIGNED_TO_SIGNED(dst, dsttype, src, srctype) \ +{ \ + srctype _tmp_src = (srctype)(src); \ + dsttype _tmp_dst = (dsttype)(_tmp_src); \ + assert(_tmp_dst >= 0); \ + assert(_tmp_src == (srctype)_tmp_dst); \ + (dst) = _tmp_dst; \ +} + +#define ASSIGN_TO_SAME_SIZE_SIGNED_TO_UNSIGNED(dst, dsttype, src, srctype) \ +{ \ + srctype _tmp_src = (srctype)(src); \ + dsttype _tmp_dst = (dsttype)(_tmp_src); \ + assert(_tmp_src >= 0); \ + assert(_tmp_src == (srctype)_tmp_dst); \ + (dst) = _tmp_dst; \ +} + +#define ASSIGN_TO_SAME_SIZE_SAME_SIGNED(dst, dsttype, src, srctype) \ + (dst) = (dsttype)(src); + +/* Include the generated overflow header file */ +#include "H5overflow.h" + +#define H5_ASSIGN_OVERFLOW(dst, src, srctype, dsttype) \ + H5_GLUE4(ASSIGN_,srctype,_TO_,dsttype)(dst,dsttype,src,srctype)\ + +#else /* NDEBUG */ +#define H5_ASSIGN_OVERFLOW(dst, src, srctype, dsttype) \ + (dst) = (dsttype)(src); +#endif /* NDEBUG */ + #if defined(H5_HAVE_WINDOW_PATH) /* directory delimiter for Windows: slash and backslash are acceptable on Windows */ |