summaryrefslogtreecommitdiffstats
path: root/src/H5encode.h
diff options
context:
space:
mode:
authorSean McBride <sean@rogue-research.com>2023-06-16 04:49:02 (GMT)
committerGitHub <noreply@github.com>2023-06-16 04:49:02 (GMT)
commit68eba3da69e659fab69bbef5901ce42e82cea1dc (patch)
treef36805f798df6c04092c14dc6803d2cb82f6eff2 /src/H5encode.h
parent10093f7c4345061bdbebc12888debbf08fe85a5b (diff)
downloadhdf5-68eba3da69e659fab69bbef5901ce42e82cea1dc.zip
hdf5-68eba3da69e659fab69bbef5901ce42e82cea1dc.tar.gz
hdf5-68eba3da69e659fab69bbef5901ce42e82cea1dc.tar.bz2
Many clang -Wextra-semi-stmt fixes (#2537)
* Adds semicolons to function-like macros * Adds a do..while(0) loop to some macros * Removes semicolons when inappropriate, especially H5E_TRY_BEGIN/END
Diffstat (limited to 'src/H5encode.h')
-rw-r--r--src/H5encode.h132
1 files changed, 68 insertions, 64 deletions
diff --git a/src/H5encode.h b/src/H5encode.h
index 6a320f1..3ec12b6 100644
--- a/src/H5encode.h
+++ b/src/H5encode.h
@@ -27,23 +27,23 @@
*/
#define INT16ENCODE(p, i) \
- { \
+ do { \
*(p) = (uint8_t)((unsigned)(i)&0xff); \
(p)++; \
*(p) = (uint8_t)(((unsigned)(i) >> 8) & 0xff); \
(p)++; \
- }
+ } while (0)
#define UINT16ENCODE(p, i) \
- { \
+ do { \
*(p) = (uint8_t)((unsigned)(i)&0xff); \
(p)++; \
*(p) = (uint8_t)(((unsigned)(i) >> 8) & 0xff); \
(p)++; \
- }
+ } while (0)
#define INT32ENCODE(p, i) \
- { \
+ do { \
*(p) = (uint8_t)((uint32_t)(i)&0xff); \
(p)++; \
*(p) = (uint8_t)(((uint32_t)(i) >> 8) & 0xff); \
@@ -52,10 +52,10 @@
(p)++; \
*(p) = (uint8_t)(((uint32_t)(i) >> 24) & 0xff); \
(p)++; \
- }
+ } while (0)
#define UINT32ENCODE(p, i) \
- { \
+ do { \
*(p) = (uint8_t)((i)&0xff); \
(p)++; \
*(p) = (uint8_t)(((i) >> 8) & 0xff); \
@@ -64,12 +64,12 @@
(p)++; \
*(p) = (uint8_t)(((i) >> 24) & 0xff); \
(p)++; \
- }
+ } while (0)
/* Encode an unsigned integer into a variable-sized buffer */
/* (Assumes that the high bits of the integer are zero) */
#define ENCODE_VAR(p, typ, n, l) \
- { \
+ do { \
typ _n = (n); \
size_t _i; \
uint8_t *_p = (uint8_t *)(p); \
@@ -77,14 +77,14 @@
for (_i = 0; _i < l; _i++, _n >>= 8) \
*_p++ = (uint8_t)(_n & 0xff); \
(p) = (uint8_t *)(p) + l; \
- }
+ } while (0)
/* Encode a 32-bit unsigned integer into a variable-sized buffer */
/* (Assumes that the high bits of the integer are zero) */
#define UINT32ENCODE_VAR(p, n, l) ENCODE_VAR(p, uint32_t, n, l)
#define INT64ENCODE(p, n) \
- { \
+ do { \
int64_t _n = (n); \
size_t _i; \
uint8_t *_p = (uint8_t *)(p); \
@@ -94,10 +94,10 @@
for (/*void*/; _i < 8; _i++) \
*_p++ = (uint8_t)((n) < 0 ? 0xff : 0); \
(p) = (uint8_t *)(p) + 8; \
- }
+ } while (0)
#define UINT64ENCODE(p, n) \
- { \
+ do { \
uint64_t _n = (n); \
size_t _i; \
uint8_t *_p = (uint8_t *)(p); \
@@ -107,21 +107,21 @@
for (/*void*/; _i < 8; _i++) \
*_p++ = 0; \
(p) = (uint8_t *)(p) + 8; \
- }
+ } while (0)
/* Encode a 64-bit unsigned integer into a variable-sized buffer */
/* (Assumes that the high bits of the integer are zero) */
#define UINT64ENCODE_VAR(p, n, l) ENCODE_VAR(p, uint64_t, n, l)
#define H5_ENCODE_UNSIGNED(p, n) \
- { \
+ do { \
HDcompile_assert(sizeof(unsigned) == sizeof(uint32_t)); \
- UINT32ENCODE(p, n) \
- }
+ UINT32ENCODE(p, n); \
+ } while (0)
/* Assumes the endianness of uint64_t is the same as double */
#define H5_ENCODE_DOUBLE(p, n) \
- { \
+ do { \
uint64_t _n; \
size_t _u; \
uint8_t *_p = (uint8_t *)(p); \
@@ -132,7 +132,7 @@
for (_u = 0; _u < sizeof(uint64_t); _u++, _n >>= 8) \
*_p++ = (uint8_t)(_n & 0xff); \
(p) = (uint8_t *)(p) + 8; \
- }
+ } while (0)
/* DECODE converts little endian bytes pointed by p to integer values and store
* it in i. For signed values, need to do sign-extension when converting
@@ -143,23 +143,23 @@
*/
#define INT16DECODE(p, i) \
- { \
+ do { \
(i) = (int16_t)((*(p)&0xff)); \
(p)++; \
(i) |= (int16_t)(((*(p)&0xff) << 8) | ((*(p)&0x80) ? ~0xffff : 0x0)); \
(p)++; \
- }
+ } while (0)
#define UINT16DECODE(p, i) \
- { \
+ do { \
(i) = (uint16_t)(*(p)&0xff); \
(p)++; \
(i) |= (uint16_t)((*(p)&0xff) << 8); \
(p)++; \
- }
+ } while (0)
#define INT32DECODE(p, i) \
- { \
+ do { \
(i) = ((int32_t)(*(p)&0xff)); \
(p)++; \
(i) |= ((int32_t)(*(p)&0xff) << 8); \
@@ -168,10 +168,10 @@
(p)++; \
(i) |= ((int32_t)(((*(p) & (unsigned)0xff) << 24) | ((*(p)&0x80) ? ~0xffffffffULL : 0x0ULL))); \
(p)++; \
- }
+ } while (0)
#define UINT32DECODE(p, i) \
- { \
+ do { \
(i) = (uint32_t)(*(p)&0xff); \
(p)++; \
(i) |= ((uint32_t)(*(p)&0xff) << 8); \
@@ -180,12 +180,12 @@
(p)++; \
(i) |= ((uint32_t)(*(p)&0xff) << 24); \
(p)++; \
- }
+ } while (0)
/* Decode a variable-sized buffer */
/* (Assumes that the high bits of the integer will be zero) */
#define DECODE_VAR(p, n, l) \
- { \
+ do { \
size_t _i; \
\
n = 0; \
@@ -193,14 +193,14 @@
for (_i = 0; _i < l; _i++) \
n = (n << 8) | *(--p); \
(p) += l; \
- }
+ } while (0)
/* Decode a variable-sized buffer into a 32-bit unsigned integer */
/* (Assumes that the high bits of the integer will be zero) */
#define UINT32DECODE_VAR(p, n, l) DECODE_VAR(p, n, l)
#define INT64DECODE(p, n) \
- { \
+ do { \
/* WE DON'T CHECK FOR OVERFLOW! */ \
size_t _i; \
\
@@ -209,10 +209,10 @@
for (_i = 0; _i < sizeof(int64_t); _i++) \
n = (n << 8) | *(--p); \
(p) += 8; \
- }
+ } while (0)
#define UINT64DECODE(p, n) \
- { \
+ do { \
/* WE DON'T CHECK FOR OVERFLOW! */ \
size_t _i; \
\
@@ -221,21 +221,21 @@
for (_i = 0; _i < sizeof(uint64_t); _i++) \
n = (n << 8) | *(--p); \
(p) += 8; \
- }
+ } while (0)
/* Decode a variable-sized buffer into a 64-bit unsigned integer */
/* (Assumes that the high bits of the integer will be zero) */
#define UINT64DECODE_VAR(p, n, l) DECODE_VAR(p, n, l)
#define H5_DECODE_UNSIGNED(p, n) \
- { \
+ do { \
HDcompile_assert(sizeof(unsigned) == sizeof(uint32_t)); \
- UINT32DECODE(p, n) \
- }
+ UINT32DECODE(p, n); \
+ } while (0)
/* Assumes the endianness of uint64_t is the same as double */
#define H5_DECODE_DOUBLE(p, n) \
- { \
+ do { \
uint64_t _n; \
size_t _u; \
\
@@ -247,37 +247,41 @@
_n = (_n << 8) | *(--p); \
HDmemcpy(&(n), &_n, sizeof(double)); \
(p) += 8; \
- }
+ } while (0)
/* Macros to encode/decode offset/length's for storing in the file */
#define H5_ENCODE_LENGTH_LEN(p, l, s) \
- switch (s) { \
- case 4: \
- UINT32ENCODE(p, l); \
- break; \
- case 8: \
- UINT64ENCODE(p, l); \
- break; \
- case 2: \
- UINT16ENCODE(p, l); \
- break; \
- default: \
- HDassert("bad sizeof size" && 0); \
- }
+ do { \
+ switch (s) { \
+ case 4: \
+ UINT32ENCODE(p, l); \
+ break; \
+ case 8: \
+ UINT64ENCODE(p, l); \
+ break; \
+ case 2: \
+ UINT16ENCODE(p, l); \
+ break; \
+ default: \
+ HDassert("bad sizeof size" && 0); \
+ } \
+ } while (0)
#define H5_DECODE_LENGTH_LEN(p, l, s) \
- switch (s) { \
- case 4: \
- UINT32DECODE(p, l); \
- break; \
- case 8: \
- UINT64DECODE(p, l); \
- break; \
- case 2: \
- UINT16DECODE(p, l); \
- break; \
- default: \
- HDassert("bad sizeof size" && 0); \
- }
+ do { \
+ switch (s) { \
+ case 4: \
+ UINT32DECODE(p, l); \
+ break; \
+ case 8: \
+ UINT64DECODE(p, l); \
+ break; \
+ case 2: \
+ UINT16DECODE(p, l); \
+ break; \
+ default: \
+ HDassert("bad sizeof size" && 0); \
+ } \
+ } while (0)
#endif /* H5encode_H */