diff --git a/src/H5FDcore.c b/src/H5FDcore.c index b1aeef9032d..408b7c57f59 100644 --- a/src/H5FDcore.c +++ b/src/H5FDcore.c @@ -103,21 +103,22 @@ typedef struct H5FD_core_fapl_t { /* These macros check for overflow of various quantities. These macros * assume that file_offset_t is signed and haddr_t and size_t are unsigned. * - * ADDR_OVERFLOW: Checks whether a file address of type `haddr_t' - * is too large to be represented by the second argument - * of the file seek function. + * CORE_ADDR_OVERFLOW: Checks whether a file address of type `haddr_t' + * is too large to be represented by the second argument + * of the file seek function. * - * SIZE_OVERFLOW: Checks whether a buffer size of type `hsize_t' is too - * large to be represented by the `size_t' type. + * CORE_SIZE_OVERFLOW: Checks whether a buffer size of type `hsize_t' is too + * large to be represented by the `size_t' type. * - * REGION_OVERFLOW: Checks whether an address and size pair describe data - * which can be addressed entirely in memory. + * CORE_REGION_OVERFLOW: Checks whether an address and size pair describe data + * which can be addressed entirely in memory. */ -#define MAXADDR ((haddr_t)((~(size_t)0) - 1)) -#define ADDR_OVERFLOW(A) (HADDR_UNDEF == (A) || (A) > (haddr_t)MAXADDR) -#define SIZE_OVERFLOW(Z) ((Z) > (hsize_t)MAXADDR) -#define REGION_OVERFLOW(A, Z) \ - (ADDR_OVERFLOW(A) || SIZE_OVERFLOW(Z) || HADDR_UNDEF == (A) + (Z) || (size_t)((A) + (Z)) < (size_t)(A)) +#define CORE_MAXADDR ((haddr_t)((~(size_t)0) - 1)) +#define CORE_ADDR_OVERFLOW(A) (HADDR_UNDEF == (A) || (A) > (haddr_t)CORE_MAXADDR) +#define CORE_SIZE_OVERFLOW(Z) ((Z) > (hsize_t)CORE_MAXADDR) +#define CORE_REGION_OVERFLOW(A, Z) \ + (CORE_ADDR_OVERFLOW(A) || CORE_SIZE_OVERFLOW(Z) || HADDR_UNDEF == (A) + (Z) || \ + (size_t)((A) + (Z)) < (size_t)(A)) /* Prototypes */ static herr_t H5FD__core_add_dirty_region(H5FD_core_t *file, haddr_t start, haddr_t end); @@ -147,7 +148,7 @@ static const H5FD_class_t H5FD_core_g = { H5FD_CLASS_VERSION, /* struct version */ H5FD_CORE_VALUE, /* value */ "core", /* name */ - MAXADDR, /* maxaddr */ + CORE_MAXADDR, /* maxaddr */ H5F_CLOSE_WEAK, /* fc_degree */ NULL, /* terminate */ NULL, /* sb_size */ @@ -707,7 +708,7 @@ H5FD__core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid file name"); if (0 == maxaddr || HADDR_UNDEF == maxaddr) HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, NULL, "bogus maxaddr"); - if (ADDR_OVERFLOW(maxaddr)) + if (CORE_ADDR_OVERFLOW(maxaddr)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, NULL, "maxaddr overflow"); assert(H5P_DEFAULT != fapl_id); if (NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id))) @@ -1155,7 +1156,7 @@ H5FD__core_set_eoa(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, haddr_t addr) FUNC_ENTER_PACKAGE - if (ADDR_OVERFLOW(addr)) + if (CORE_ADDR_OVERFLOW(addr)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "address overflow"); file->eoa = addr; @@ -1271,7 +1272,7 @@ H5FD__core_read(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNU /* Check for overflow conditions */ if (HADDR_UNDEF == addr) HGOTO_ERROR(H5E_IO, H5E_OVERFLOW, FAIL, "file address overflowed"); - if (REGION_OVERFLOW(addr, size)) + if (CORE_REGION_OVERFLOW(addr, size)) HGOTO_ERROR(H5E_IO, H5E_OVERFLOW, FAIL, "file address overflowed"); /* Read the part which is before the EOF marker */ @@ -1325,7 +1326,7 @@ H5FD__core_write(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UN assert(buf); /* Check for overflow conditions */ - if (REGION_OVERFLOW(addr, size)) + if (CORE_REGION_OVERFLOW(addr, size)) HGOTO_ERROR(H5E_IO, H5E_OVERFLOW, FAIL, "file address overflowed"); /* diff --git a/src/H5FDdirect.c b/src/H5FDdirect.c index 147013f7c95..ba287b9d4a4 100644 --- a/src/H5FDdirect.c +++ b/src/H5FDdirect.c @@ -90,27 +90,6 @@ typedef struct H5FD_direct_t { } H5FD_direct_t; -/* - * These macros check for overflow of various quantities. These macros - * assume that HDoff_t is signed and haddr_t and size_t are unsigned. - * - * ADDR_OVERFLOW: Checks whether a file address of type `haddr_t' - * is too large to be represented by the second argument - * of the file seek function. - * - * SIZE_OVERFLOW: Checks whether a buffer size of type `hsize_t' is too - * large to be represented by the `size_t' type. - * - * REGION_OVERFLOW: Checks whether an address and size pair describe data - * which can be addressed entirely by the second - * argument of the file seek function. - */ -#define MAXADDR (((haddr_t)1 << (8 * sizeof(HDoff_t) - 1)) - 1) -#define ADDR_OVERFLOW(A) (HADDR_UNDEF == (A) || ((A) & ~(haddr_t)MAXADDR)) -#define SIZE_OVERFLOW(Z) ((Z) & ~(hsize_t)MAXADDR) -#define REGION_OVERFLOW(A, Z) \ - (ADDR_OVERFLOW(A) || SIZE_OVERFLOW(Z) || HADDR_UNDEF == (A) + (Z) || (HDoff_t)((A) + (Z)) < (HDoff_t)(A)) - /* Prototypes */ static herr_t H5FD__direct_populate_config(size_t boundary, size_t block_size, size_t cbuf_size, H5FD_direct_fapl_t *fa_out); @@ -137,7 +116,7 @@ static const H5FD_class_t H5FD_direct_g = { H5FD_CLASS_VERSION, /* struct version */ H5FD_DIRECT_VALUE, /* value */ "direct", /* name */ - MAXADDR, /* maxaddr */ + H5FD_MAXADDR, /* maxaddr */ H5F_CLOSE_WEAK, /* fc_degree */ NULL, /* terminate */ NULL, /* sb_size */ @@ -436,7 +415,7 @@ H5FD__direct_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxad HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid file name"); if (0 == maxaddr || HADDR_UNDEF == maxaddr) HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, NULL, "bogus maxaddr"); - if (ADDR_OVERFLOW(maxaddr)) + if (H5FD_ADDR_OVERFLOW(maxaddr)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, NULL, "bogus maxaddr"); /* Build the open flags */ @@ -818,7 +797,7 @@ H5FD__direct_read(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_U /* Check for overflow conditions */ if (HADDR_UNDEF == addr) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "addr undefined"); - if (REGION_OVERFLOW(addr, size)) + if (H5FD_REGION_OVERFLOW(addr, size)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow"); /* If the system doesn't require data to be aligned, read the data in @@ -998,7 +977,7 @@ H5FD__direct_write(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_ /* Check for overflow conditions */ if (HADDR_UNDEF == addr) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "addr undefined"); - if (REGION_OVERFLOW(addr, size)) + if (H5FD_REGION_OVERFLOW(addr, size)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow"); /* If the system doesn't require data to be aligned, read the data in diff --git a/src/H5FDhdfs.c b/src/H5FDhdfs.c index e217948137b..615067d1e22 100644 --- a/src/H5FDhdfs.c +++ b/src/H5FDhdfs.c @@ -230,19 +230,6 @@ typedef struct H5FD_hdfs_t { #endif } H5FD_hdfs_t; -/* - * These macros check for overflow of various quantities. These macros - * assume that HDoff_t is signed and haddr_t and size_t are unsigned. - * - * ADDR_OVERFLOW: Checks whether a file address of type `haddr_t' - * is too large to be represented by the second argument - * of the file seek function. - * Only included if HDFS code should compile. - * - */ -#define MAXADDR (((haddr_t)1 << (8 * sizeof(HDoff_t) - 1)) - 1) -#define ADDR_OVERFLOW(A) (HADDR_UNDEF == (A) || ((A) & ~(haddr_t)MAXADDR)) - /* Prototypes */ static void *H5FD__hdfs_fapl_get(H5FD_t *_file); static void *H5FD__hdfs_fapl_copy(const void *_old_fa); @@ -267,7 +254,7 @@ static const H5FD_class_t H5FD_hdfs_g = { H5FD_CLASS_VERSION, /* struct version */ H5FD_HDFS_VALUE, /* value */ "hdfs", /* name */ - MAXADDR, /* maxaddr */ + H5FD_MAXADDR, /* maxaddr */ H5F_CLOSE_WEAK, /* fc_degree */ NULL, /* terminate */ NULL, /* sb_size */ @@ -840,7 +827,7 @@ H5FD__hdfs_open(const char *path, unsigned flags, hid_t fapl_id, haddr_t maxaddr HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid file name"); if (0 == maxaddr || HADDR_UNDEF == maxaddr) HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, NULL, "bogus maxaddr"); - if (ADDR_OVERFLOW(maxaddr)) + if (H5FD_ADDR_OVERFLOW(maxaddr)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, NULL, "bogus maxaddr"); if (flags != H5F_ACC_RDONLY) HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, NULL, "only Read-Only access allowed"); diff --git a/src/H5FDlog.c b/src/H5FDlog.c index 13e64ef939c..f3877f684ed 100644 --- a/src/H5FDlog.c +++ b/src/H5FDlog.c @@ -129,27 +129,6 @@ typedef struct H5FD_log_t { H5FD_log_fapl_t fa; /* Driver-specific file access properties */ } H5FD_log_t; -/* - * These macros check for overflow of various quantities. These macros - * assume that HDoff_t is signed and haddr_t and size_t are unsigned. - * - * ADDR_OVERFLOW: Checks whether a file address of type `haddr_t' - * is too large to be represented by the second argument - * of the file seek function. - * - * SIZE_OVERFLOW: Checks whether a buffer size of type `hsize_t' is too - * large to be represented by the `size_t' type. - * - * REGION_OVERFLOW: Checks whether an address and size pair describe data - * which can be addressed entirely by the second - * argument of the file seek function. - */ -#define MAXADDR (((haddr_t)1 << (8 * sizeof(HDoff_t) - 1)) - 1) -#define ADDR_OVERFLOW(A) (HADDR_UNDEF == (A) || ((A) & ~(haddr_t)MAXADDR)) -#define SIZE_OVERFLOW(Z) ((Z) & ~(hsize_t)MAXADDR) -#define REGION_OVERFLOW(A, Z) \ - (ADDR_OVERFLOW(A) || SIZE_OVERFLOW(Z) || HADDR_UNDEF == (A) + (Z) || (HDoff_t)((A) + (Z)) < (HDoff_t)(A)) - /* Prototypes */ static void *H5FD__log_fapl_get(H5FD_t *file); static void *H5FD__log_fapl_copy(const void *_old_fa); @@ -177,7 +156,7 @@ static const H5FD_class_t H5FD_log_g = { H5FD_CLASS_VERSION, /* struct version */ H5FD_LOG_VALUE, /* value */ "log", /* name */ - MAXADDR, /* maxaddr */ + H5FD_MAXADDR, /* maxaddr */ H5F_CLOSE_WEAK, /* fc_degree */ NULL, /* terminate */ NULL, /* sb_size */ @@ -450,7 +429,7 @@ H5FD__log_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid file name"); if (0 == maxaddr || HADDR_UNDEF == maxaddr) HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, NULL, "bogus maxaddr"); - if (ADDR_OVERFLOW(maxaddr)) + if (H5FD_ADDR_OVERFLOW(maxaddr)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, NULL, "bogus maxaddr"); /* Initialize timers */ @@ -1120,7 +1099,7 @@ H5FD__log_read(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, had /* Check for overflow conditions */ if (!H5_addr_defined(addr)) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "addr undefined, addr = %llu", (unsigned long long)addr); - if (REGION_OVERFLOW(addr, size)) + if (H5FD_REGION_OVERFLOW(addr, size)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow, addr = %llu", (unsigned long long)addr); /* Log the I/O information about the read */ @@ -1344,7 +1323,7 @@ H5FD__log_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, ha /* Check for overflow conditions */ if (!H5_addr_defined(addr)) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "addr undefined, addr = %llu", (unsigned long long)addr); - if (REGION_OVERFLOW(addr, size)) + if (H5FD_REGION_OVERFLOW(addr, size)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow, addr = %llu, size = %llu", (unsigned long long)addr, (unsigned long long)size); diff --git a/src/H5FDmirror.c b/src/H5FDmirror.c index 5e4ccd7cc9b..d566eafe080 100644 --- a/src/H5FDmirror.c +++ b/src/H5FDmirror.c @@ -45,24 +45,6 @@ typedef struct H5FD_mirror_t { uint32_t xmit_i; /* Counter of transmission sent and rec'd */ } H5FD_mirror_t; -/* - * These macros check for overflow of various quantities. These macros - * assume that HDoff_t is signed and haddr_t and size_t are unsigned. - * - * ADDR_OVERFLOW: Checks whether a file address of type `haddr_t' - * is too large to be represented by the second argument - * of the file seek function. - * - * SIZE_OVERFLOW: Checks whether a buffer size of type `hsize_t' is too - * large to be represented by the `size_t' type. - * - * REGION_OVERFLOW: Checks whether an address and size pair describe data - * which can be addressed entirely by the second - * argument of the file seek function. - */ -#define MAXADDR (((haddr_t)1 << (8 * sizeof(HDoff_t) - 1)) - 1) -#define ADDR_OVERFLOW(A) (HADDR_UNDEF == (A) || ((A) & ~(haddr_t)MAXADDR)) - #ifndef BSWAP_64 #define BSWAP_64(X) \ (uint64_t)((((X) & 0x00000000000000FF) << 56) | (((X) & 0x000000000000FF00) << 40) | \ @@ -162,7 +144,7 @@ static const H5FD_class_t H5FD_mirror_g = { H5FD_CLASS_VERSION, /* struct version */ H5FD_MIRROR_VALUE, /* value */ "mirror", /* name */ - MAXADDR, /* maxaddr */ + H5FD_MAXADDR, /* maxaddr */ H5F_CLOSE_WEAK, /* fc_degree */ NULL, /* terminate */ NULL, /* sb_size */ @@ -1358,7 +1340,7 @@ H5FD__mirror_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxad HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "filename is too long"); if (0 == maxaddr || HADDR_UNDEF == maxaddr) HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, NULL, "bogus maxaddr"); - if (ADDR_OVERFLOW(maxaddr)) + if (H5FD_ADDR_OVERFLOW(maxaddr)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, NULL, "bogus maxaddr"); if (H5Pget_fapl_mirror(fapl_id, &fa) == FAIL) diff --git a/src/H5FDonion.c b/src/H5FDonion.c index c9b2567f25c..ddbc25bc04c 100644 --- a/src/H5FDonion.c +++ b/src/H5FDonion.c @@ -147,8 +147,6 @@ typedef struct H5FD_onion_t { H5FL_DEFINE_STATIC(H5FD_onion_t); -#define MAXADDR (((haddr_t)1 << (8 * sizeof(HDoff_t) - 1)) - 1) - #define H5FD_CTL_GET_NUM_REVISIONS 20001 /* Prototypes */ @@ -175,7 +173,7 @@ static const H5FD_class_t H5FD_onion_g = { H5FD_CLASS_VERSION, /* struct version */ H5FD_ONION_VALUE, /* value */ "onion", /* name */ - MAXADDR, /* maxaddr */ + H5FD_MAXADDR, /* maxaddr */ H5F_CLOSE_WEAK, /* fc_degree */ NULL, /* terminate */ H5FD__onion_sb_size, /* sb_size */ diff --git a/src/H5FDpkg.h b/src/H5FDpkg.h index 2ba842df456..ee8ac1cc5f5 100644 --- a/src/H5FDpkg.h +++ b/src/H5FDpkg.h @@ -31,6 +31,30 @@ /* Package Private Macros */ /**************************/ +/* These macros check for overflow of various quantities. They are suitable + * for VFDs that are "file-like" where lseek(2), etc. is used to move around + * via HDoff_t units (i.e., most VFDs aside from the core VFD). + * + * These macros assume that HDoff_t is signed and haddr_t and size_t are unsigned. + * + * H5FD_ADDR_OVERFLOW: Checks whether a file address of type `haddr_t' + * is too large to be represented by the second argument + * of the file seek function. + * + * H5FD_SIZE_OVERFLOW: Checks whether a buffer size of type `hsize_t' is too + * large to be represented by the `size_t' type. + * + * H5FD_REGION_OVERFLOW: Checks whether an address and size pair describe data + * which can be addressed entirely by the second + * argument of the file seek function. + */ +#define H5FD_MAXADDR (((haddr_t)1 << (8 * sizeof(HDoff_t) - 1)) - 1) +#define H5FD_ADDR_OVERFLOW(A) (HADDR_UNDEF == (A) || ((A) & ~(haddr_t)H5FD_MAXADDR)) +#define H5FD_SIZE_OVERFLOW(Z) ((Z) & ~(hsize_t)H5FD_MAXADDR) +#define H5FD_REGION_OVERFLOW(A, Z) \ + (H5FD_ADDR_OVERFLOW(A) || H5FD_SIZE_OVERFLOW(Z) || HADDR_UNDEF == (A) + (Z) || \ + (HDoff_t)((A) + (Z)) < (HDoff_t)(A)) + /****************************/ /* Package Private Typedefs */ /****************************/ diff --git a/src/H5FDros3.c b/src/H5FDros3.c index 253024e0d4a..02698c59399 100644 --- a/src/H5FDros3.c +++ b/src/H5FDros3.c @@ -129,18 +129,6 @@ typedef struct H5FD_ros3_t { #endif } H5FD_ros3_t; -/* These macros check for overflow of various quantities. These macros - * assume that HDoff_t is signed and haddr_t and size_t are unsigned. - * - * ADDR_OVERFLOW: Checks whether a file address of type `haddr_t' - * is too large to be represented by the second argument - * of the file seek function. - * Only included if it may be used -- ROS3 VFD is enabled. - * - */ -#define MAXADDR (((haddr_t)1 << (8 * sizeof(HDoff_t) - 1)) - 1) -#define ADDR_OVERFLOW(A) (HADDR_UNDEF == (A) || ((A) & ~(haddr_t)MAXADDR)) - /* Prototypes */ static void *H5FD__ros3_fapl_get(H5FD_t *_file); static void *H5FD__ros3_fapl_copy(const void *_old_fa); @@ -176,7 +164,7 @@ static const H5FD_class_t H5FD_ros3_g = { H5FD_CLASS_VERSION, /* struct version */ H5FD_ROS3_VALUE, /* value */ "ros3", /* name */ - MAXADDR, /* maxaddr */ + H5FD_MAXADDR, /* maxaddr */ H5F_CLOSE_WEAK, /* fc_degree */ NULL, /* terminate */ NULL, /* sb_size */ @@ -725,7 +713,7 @@ H5FD__ros3_open(const char *url, unsigned flags, hid_t fapl_id, haddr_t maxaddr) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid file name"); if (0 == maxaddr || HADDR_UNDEF == maxaddr) HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, NULL, "bogus maxaddr"); - if (ADDR_OVERFLOW(maxaddr)) + if (H5FD_ADDR_OVERFLOW(maxaddr)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, NULL, "bogus maxaddr"); if (flags != H5F_ACC_RDONLY) HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, NULL, "only Read-Only access allowed"); diff --git a/src/H5FDsec2.c b/src/H5FDsec2.c index fa9c8849803..0475f9a7647 100644 --- a/src/H5FDsec2.c +++ b/src/H5FDsec2.c @@ -94,27 +94,6 @@ typedef struct H5FD_sec2_t { bool fam_to_single; } H5FD_sec2_t; -/* - * These macros check for overflow of various quantities. These macros - * assume that HDoff_t is signed and haddr_t and size_t are unsigned. - * - * ADDR_OVERFLOW: Checks whether a file address of type `haddr_t' - * is too large to be represented by the second argument - * of the file seek function. - * - * SIZE_OVERFLOW: Checks whether a buffer size of type `hsize_t' is too - * large to be represented by the `size_t' type. - * - * REGION_OVERFLOW: Checks whether an address and size pair describe data - * which can be addressed entirely by the second - * argument of the file seek function. - */ -#define MAXADDR (((haddr_t)1 << (8 * sizeof(HDoff_t) - 1)) - 1) -#define ADDR_OVERFLOW(A) (HADDR_UNDEF == (A) || ((A) & ~(haddr_t)MAXADDR)) -#define SIZE_OVERFLOW(Z) ((Z) & ~(hsize_t)MAXADDR) -#define REGION_OVERFLOW(A, Z) \ - (ADDR_OVERFLOW(A) || SIZE_OVERFLOW(Z) || HADDR_UNDEF == (A) + (Z) || (HDoff_t)((A) + (Z)) < (HDoff_t)(A)) - /* Prototypes */ static H5FD_t *H5FD__sec2_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr); static herr_t H5FD__sec2_close(H5FD_t *_file); @@ -139,7 +118,7 @@ static const H5FD_class_t H5FD_sec2_g = { H5FD_CLASS_VERSION, /* struct version */ H5FD_SEC2_VALUE, /* value */ "sec2", /* name */ - MAXADDR, /* maxaddr */ + H5FD_MAXADDR, /* maxaddr */ H5F_CLOSE_WEAK, /* fc_degree */ NULL, /* terminate */ NULL, /* sb_size */ @@ -288,7 +267,7 @@ H5FD__sec2_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid file name"); if (0 == maxaddr || HADDR_UNDEF == maxaddr) HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, NULL, "bogus maxaddr"); - if (ADDR_OVERFLOW(maxaddr)) + if (H5FD_ADDR_OVERFLOW(maxaddr)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, NULL, "bogus maxaddr"); /* Build the open flags */ @@ -644,7 +623,7 @@ H5FD__sec2_read(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNU /* Check for overflow conditions */ if (!H5_addr_defined(addr)) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "addr undefined, addr = %llu", (unsigned long long)addr); - if (REGION_OVERFLOW(addr, size)) + if (H5FD_REGION_OVERFLOW(addr, size)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow, addr = %llu", (unsigned long long)addr); #ifndef H5_HAVE_PREADWRITE @@ -754,7 +733,7 @@ H5FD__sec2_write(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UN /* Check for overflow conditions */ if (!H5_addr_defined(addr)) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "addr undefined, addr = %llu", (unsigned long long)addr); - if (REGION_OVERFLOW(addr, size)) + if (H5FD_REGION_OVERFLOW(addr, size)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow, addr = %llu, size = %llu", (unsigned long long)addr, (unsigned long long)size); diff --git a/src/H5FDsplitter.c b/src/H5FDsplitter.c index cee2163fe5b..495328c40eb 100644 --- a/src/H5FDsplitter.c +++ b/src/H5FDsplitter.c @@ -50,27 +50,6 @@ typedef struct H5FD_splitter_t { FILE *logfp; /* Log file pointer */ } H5FD_splitter_t; -/* - * These macros check for overflow of various quantities. These macros - * assume that HDoff_t is signed and haddr_t and size_t are unsigned. - * - * ADDR_OVERFLOW: Checks whether a file address of type `haddr_t' - * is too large to be represented by the second argument - * of the file seek function. - * - * SIZE_OVERFLOW: Checks whether a buffer size of type `hsize_t' is too - * large to be represented by the `size_t' type. - * - * REGION_OVERFLOW: Checks whether an address and size pair describe data - * which can be addressed entirely by the second - * argument of the file seek function. - */ -#define MAXADDR (((haddr_t)1 << (8 * sizeof(HDoff_t) - 1)) - 1) -#define ADDR_OVERFLOW(A) (HADDR_UNDEF == (A) || ((A) & ~(haddr_t)MAXADDR)) -#define SIZE_OVERFLOW(Z) ((Z) & ~(hsize_t)MAXADDR) -#define REGION_OVERFLOW(A, Z) \ - (ADDR_OVERFLOW(A) || SIZE_OVERFLOW(Z) || HADDR_UNDEF == (A) + (Z) || (HDoff_t)((A) + (Z)) < (HDoff_t)(A)) - /* This macro provides a wrapper for shared fail-log-ignore behavior * for errors arising in the splitter's W/O channel. * Logs an error entry in a log file, if the file exists. @@ -139,7 +118,7 @@ static const H5FD_class_t H5FD_splitter_g = { H5FD_CLASS_VERSION, /* struct version */ H5FD_SPLITTER_VALUE, /* value */ "splitter", /* name */ - MAXADDR, /* maxaddr */ + H5FD_MAXADDR, /* maxaddr */ H5F_CLOSE_WEAK, /* fc_degree */ NULL, /* terminate */ H5FD__splitter_sb_size, /* sb_size */ @@ -615,7 +594,7 @@ H5FD__splitter_read(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR /* Check for overflow conditions */ if (!H5_addr_defined(addr)) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "addr undefined, addr = %llu", (unsigned long long)addr); - if (REGION_OVERFLOW(addr, size)) + if (H5FD_REGION_OVERFLOW(addr, size)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow, addr = %llu", (unsigned long long)addr); /* Only read from R/W channel */ @@ -798,7 +777,7 @@ H5FD__splitter_open(const char *name, unsigned flags, hid_t splitter_fapl_id, ha HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid file name"); if (0 == maxaddr || HADDR_UNDEF == maxaddr) HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, NULL, "bogus maxaddr"); - if (ADDR_OVERFLOW(maxaddr)) + if (H5FD_ADDR_OVERFLOW(maxaddr)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, NULL, "bogus maxaddr"); if (H5FD_SPLITTER != H5Pget_driver(splitter_fapl_id)) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "driver is not splitter"); diff --git a/src/H5FDstdio.c b/src/H5FDstdio.c index 611ae554ba4..9de221120ef 100644 --- a/src/H5FDstdio.c +++ b/src/H5FDstdio.c @@ -142,22 +142,23 @@ typedef struct H5FD_stdio_t { /* These macros check for overflow of various quantities. These macros * assume that HDoff_t is signed and haddr_t and size_t are unsigned. * - * ADDR_OVERFLOW: Checks whether a file address of type `haddr_t' - * is too large to be represented by the second argument - * of the file seek function. + * MY_ADDR_OVERFLOW: Checks whether a file address of type `haddr_t' + * is too large to be represented by the second argument + * of the file seek function. * - * SIZE_OVERFLOW: Checks whether a buffer size of type `hsize_t' is too - * large to be represented by the `size_t' type. + * MY_SIZE_OVERFLOW: Checks whether a buffer size of type `hsize_t' is too + * large to be represented by the `size_t' type. * - * REGION_OVERFLOW: Checks whether an address and size pair describe data - * which can be addressed entirely by the second - * argument of the file seek function. + * MY_REGION_OVERFLOW: Checks whether an address and size pair describe data + * which can be addressed entirely by the second + * argument of the file seek function. */ -#define MAXADDR (((haddr_t)1 << (8 * sizeof(HDoff_t) - 1)) - 1) -#define ADDR_OVERFLOW(A) (HADDR_UNDEF == (A) || ((A) & ~(haddr_t)MAXADDR)) -#define SIZE_OVERFLOW(Z) ((Z) & ~(hsize_t)MAXADDR) -#define REGION_OVERFLOW(A, Z) \ - (ADDR_OVERFLOW(A) || SIZE_OVERFLOW(Z) || HADDR_UNDEF == (A) + (Z) || (HDoff_t)((A) + (Z)) < (HDoff_t)(A)) +#define MY_MAXADDR (((haddr_t)1 << (8 * sizeof(HDoff_t) - 1)) - 1) +#define MY_ADDR_OVERFLOW(A) (HADDR_UNDEF == (A) || ((A) & ~(haddr_t)MY_MAXADDR)) +#define MY_SIZE_OVERFLOW(Z) ((Z) & ~(hsize_t)MY_MAXADDR) +#define MY_REGION_OVERFLOW(A, Z) \ + (MY_ADDR_OVERFLOW(A) || MY_SIZE_OVERFLOW(Z) || HADDR_UNDEF == (A) + (Z) || \ + (HDoff_t)((A) + (Z)) < (HDoff_t)(A)) /* Prototypes */ static H5FD_t *H5FD_stdio_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr); @@ -183,7 +184,7 @@ const H5FD_class_t H5FD_stdio_g = { H5FD_CLASS_VERSION, /* struct version */ H5_VFD_STDIO, /* value */ "stdio", /* name */ - MAXADDR, /* maxaddr */ + MY_MAXADDR, /* maxaddr */ H5F_CLOSE_WEAK, /* fc_degree */ NULL, /* terminate */ NULL, /* sb_size */ @@ -327,7 +328,7 @@ H5FD_stdio_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr H5Epush_ret(__func__, H5E_ERR_CLS, H5E_ARGS, H5E_BADVALUE, "invalid file name", NULL); if (0 == maxaddr || HADDR_UNDEF == maxaddr) H5Epush_ret(__func__, H5E_ERR_CLS, H5E_ARGS, H5E_BADRANGE, "bogus maxaddr", NULL); - if (ADDR_OVERFLOW(maxaddr)) + if (MY_ADDR_OVERFLOW(maxaddr)) H5Epush_ret(__func__, H5E_ERR_CLS, H5E_ARGS, H5E_OVERFLOW, "maxaddr too large", NULL); /* Tentatively open file in read-only mode, to check for existence */ @@ -751,7 +752,7 @@ H5FD_stdio_read(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, hid_t /*UNUSED*/ dxpl /* Check for overflow */ if (HADDR_UNDEF == addr) H5Epush_ret(__func__, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed", -1); - if (REGION_OVERFLOW(addr, size)) + if (MY_REGION_OVERFLOW(addr, size)) H5Epush_ret(__func__, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed", -1); /* Check easy cases */ @@ -850,7 +851,7 @@ H5FD_stdio_write(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, hid_t /*UNUSED*/ dxp /* Check for overflow conditions */ if (HADDR_UNDEF == addr) H5Epush_ret(__func__, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed", -1); - if (REGION_OVERFLOW(addr, size)) + if (MY_REGION_OVERFLOW(addr, size)) H5Epush_ret(__func__, H5E_ERR_CLS, H5E_IO, H5E_OVERFLOW, "file address overflowed", -1); /* Seek to the correct file position. */ diff --git a/src/H5FDsubfiling/H5FDioc.c b/src/H5FDsubfiling/H5FDioc.c index ae42b3b58a1..e1c61883169 100644 --- a/src/H5FDsubfiling/H5FDioc.c +++ b/src/H5FDsubfiling/H5FDioc.c @@ -69,27 +69,6 @@ typedef struct H5FD_ioc_t { char *file_path; /* The user defined filename */ } H5FD_ioc_t; -/* - * These macros check for overflow of various quantities. These macros - * assume that HDoff_t is signed and haddr_t and size_t are unsigned. - * - * ADDR_OVERFLOW: Checks whether a file address of type `haddr_t' - * is too large to be represented by the second argument - * of the file seek function. - * - * SIZE_OVERFLOW: Checks whether a buffer size of type `hsize_t' is too - * large to be represented by the `size_t' type. - * - * REGION_OVERFLOW: Checks whether an address and size pair describe data - * which can be addressed entirely by the second - * argument of the file seek function. - */ -#define MAXADDR (((haddr_t)1 << (8 * sizeof(HDoff_t) - 1)) - 1) -#define ADDR_OVERFLOW(A) (HADDR_UNDEF == (A) || ((A) & ~(haddr_t)MAXADDR)) -#define SIZE_OVERFLOW(Z) ((Z) & ~(hsize_t)MAXADDR) -#define REGION_OVERFLOW(A, Z) \ - (ADDR_OVERFLOW(A) || SIZE_OVERFLOW(Z) || HADDR_UNDEF == (A) + (Z) || (HDoff_t)((A) + (Z)) < (HDoff_t)(A)) - /* Private functions */ /* Prototypes */ static herr_t H5FD__ioc_term(void); @@ -135,7 +114,7 @@ static const H5FD_class_t H5FD_ioc_g = { H5FD_CLASS_VERSION, /* VFD interface version */ H5_VFD_IOC, /* value */ H5FD_IOC_NAME, /* name */ - MAXADDR, /* maxaddr */ + H5FD_MAXADDR, /* maxaddr */ H5F_CLOSE_WEAK, /* fc_degree */ H5FD__ioc_term, /* terminate */ H5FD__ioc_sb_size, /* sb_size */ @@ -719,7 +698,7 @@ H5FD__ioc_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid file name"); if (0 == maxaddr || HADDR_UNDEF == maxaddr) HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, NULL, "bogus maxaddr"); - if (ADDR_OVERFLOW(maxaddr)) + if (H5FD_ADDR_OVERFLOW(maxaddr)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, NULL, "bogus maxaddr"); /* Initialize driver, if it's not yet */ @@ -1110,7 +1089,7 @@ H5FD__ioc_read(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNUS /* Check for overflow conditions */ if (!H5_addr_defined(addr)) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "addr undefined, addr = %" PRIuHADDR, addr); - if (REGION_OVERFLOW(addr, size)) + if (H5FD_REGION_OVERFLOW(addr, size)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow, addr = %" PRIuHADDR, addr); if (H5FD__ioc_read_vector_internal(file, 1, &addr, &size, &buf) < 0) diff --git a/src/H5FDsubfiling/H5FDsubfiling.c b/src/H5FDsubfiling/H5FDsubfiling.c index 42891bb1bc4..8deb746cfa0 100644 --- a/src/H5FDsubfiling/H5FDsubfiling.c +++ b/src/H5FDsubfiling/H5FDsubfiling.c @@ -129,27 +129,6 @@ typedef enum H5FD_subfiling_io_type_t { IO_TYPE_READ, } H5FD_subfiling_io_type_t; -/* - * These macros check for overflow of various quantities. These macros - * assume that HDoff_t is signed and haddr_t and size_t are unsigned. - * - * ADDR_OVERFLOW: Checks whether a file address of type `haddr_t' - * is too large to be represented by the second argument - * of the file seek function. - * - * SIZE_OVERFLOW: Checks whether a buffer size of type `hsize_t' is too - * large to be represented by the `size_t' type. - * - * REGION_OVERFLOW: Checks whether an address and size pair describe data - * which can be addressed entirely by the second - * argument of the file seek function. - */ -#define MAXADDR (((haddr_t)1 << (8 * sizeof(HDoff_t) - 1)) - 1) -#define ADDR_OVERFLOW(A) (HADDR_UNDEF == (A) || ((A) & ~(haddr_t)MAXADDR)) -#define SIZE_OVERFLOW(Z) ((Z) & ~(hsize_t)MAXADDR) -#define REGION_OVERFLOW(A, Z) \ - (ADDR_OVERFLOW(A) || SIZE_OVERFLOW(Z) || HADDR_UNDEF == (A) + (Z) || (HDoff_t)((A) + (Z)) < (HDoff_t)(A)) - /* * NOTE: Must be kept in sync with the private * H5F_MAX_DRVINFOBLOCK_SIZE macro value for now @@ -245,7 +224,7 @@ static const H5FD_class_t H5FD_subfiling_g = { H5FD_CLASS_VERSION, /* VFD interface version */ H5_VFD_SUBFILING, /* value */ H5FD_SUBFILING_NAME, /* name */ - MAXADDR, /* maxaddr */ + H5FD_MAXADDR, /* maxaddr */ H5F_CLOSE_WEAK, /* fc_degree */ H5FD__subfiling_term, /* terminate */ H5FD__subfiling_sb_size, /* sb_size */ @@ -1127,7 +1106,7 @@ H5FD__subfiling_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t ma HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid file name"); if (0 == maxaddr || HADDR_UNDEF == maxaddr) HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, NULL, "bogus maxaddr"); - if (ADDR_OVERFLOW(maxaddr)) + if (H5FD_ADDR_OVERFLOW(maxaddr)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, NULL, "bogus maxaddr"); /* Initialize driver, if it's not yet */ @@ -1954,7 +1933,7 @@ H5FD__subfiling_io_helper(H5FD_subfiling_t *file, size_t io_count, H5FD_mem_t ty if (!H5_addr_defined(addrs[i])) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "addr[%zu] undefined, addr = %" PRIuHADDR, i, addrs[i]); - if (REGION_OVERFLOW(addrs[i], io_size)) + if (H5FD_REGION_OVERFLOW(addrs[i], io_size)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr[%zu] overflow, addr = %" PRIuHADDR ", size = %zu", i, addrs[i], io_size); if ((addrs[i] + io_size) > file_eoa)