summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDana Robinson <43805+derobins@users.noreply.github.com>2023-07-27 19:26:17 (GMT)
committerGitHub <noreply@github.com>2023-07-27 19:26:17 (GMT)
commit95e5349089b95dfb95f0f8ce2d6db1bc04ba6c82 (patch)
treef2bd0c1f37cf3b15b4ce199984fbe164a276f88e /src
parentdf5dcb2a735dd5bb3ee2cc700119109605976e41 (diff)
downloadhdf5-95e5349089b95dfb95f0f8ce2d6db1bc04ba6c82.zip
hdf5-95e5349089b95dfb95f0f8ce2d6db1bc04ba6c82.tar.gz
hdf5-95e5349089b95dfb95f0f8ce2d6db1bc04ba6c82.tar.bz2
Misc warnings and cross-compile improvements (#3281)
Diffstat (limited to 'src')
-rw-r--r--src/H5Iint.c8
-rw-r--r--src/H5SL.c10
-rw-r--r--src/H5T.c32
-rw-r--r--src/H5Tconv.c24
-rw-r--r--src/H5system.c1
5 files changed, 48 insertions, 27 deletions
diff --git a/src/H5Iint.c b/src/H5Iint.c
index 5ffac4d..8a6b7ae 100644
--- a/src/H5Iint.c
+++ b/src/H5Iint.c
@@ -389,9 +389,9 @@ H5I__mark_node(void *_info, void H5_ATTR_UNUSED *key, void *_udata)
#ifdef H5I_DEBUG
if (H5DEBUG(I)) {
HDfprintf(H5DEBUG(I),
- "H5I: discard type=%d obj=0x%08lx "
+ "H5I: discard type=%d obj=%p "
"failure ignored\n",
- (int)udata->type_info->cls->type, (unsigned long)(info->object));
+ (int)udata->type_info->cls->type, info->object);
}
#endif /* H5I_DEBUG */
@@ -412,9 +412,9 @@ H5I__mark_node(void *_info, void H5_ATTR_UNUSED *key, void *_udata)
#ifdef H5I_DEBUG
if (H5DEBUG(I)) {
HDfprintf(H5DEBUG(I),
- "H5I: free type=%d obj=0x%08lx "
+ "H5I: free type=%d obj=%p "
"failure ignored\n",
- (int)udata->type_info->cls->type, (unsigned long)(info->object));
+ (int)udata->type_info->cls->type, info->object);
}
#endif /* H5I_DEBUG */
diff --git a/src/H5SL.c b/src/H5SL.c
index fbd0b0d..11ccb9f 100644
--- a/src/H5SL.c
+++ b/src/H5SL.c
@@ -156,9 +156,9 @@
#define H5SL_GROW(X, LVL, ERR) \
{ \
/* Check if we need to increase allocation of forward pointers */ \
- if (LVL + 1 >= 1u << X->log_nalloc) { \
+ if (LVL + 1 >= ((size_t)1) << X->log_nalloc) { \
H5SL_node_t **_tmp; \
- HDassert(LVL + 1 == 1U << X->log_nalloc); \
+ HDassert(LVL + 1 == ((size_t)1) << X->log_nalloc); \
/* Double the amount of allocated space */ \
X->log_nalloc++; \
\
@@ -178,7 +178,7 @@
\
/* Create the new factory */ \
H5SL_fac_g[H5SL_fac_nused_g] = \
- H5FL_fac_init((1u << H5SL_fac_nused_g) * sizeof(H5SL_node_t *)); \
+ H5FL_fac_init((((size_t)1) << H5SL_fac_nused_g) * sizeof(H5SL_node_t *)); \
H5SL_fac_nused_g++; \
} \
\
@@ -198,9 +198,9 @@
#define H5SL_SHRINK(X, LVL) \
{ \
/* Check if we can reduce the allocation of forward pointers */ \
- if (LVL <= 1u << (X->log_nalloc - 1)) { \
+ if (LVL <= ((size_t)1) << (X->log_nalloc - 1)) { \
H5SL_node_t **_tmp; \
- HDassert(LVL == 1U << (X->log_nalloc - 1)); \
+ HDassert(LVL == ((size_t)1) << (X->log_nalloc - 1)); \
X->log_nalloc--; \
\
/* Allocate space for new forward pointers */ \
diff --git a/src/H5T.c b/src/H5T.c
index 7e85227..9cbf546 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -1503,9 +1503,9 @@ H5T_top_term_package(void)
if (H5DEBUG(T)) {
HDfprintf(H5DEBUG(T),
"H5T: conversion function "
- "0x%08lx failed to free private data for "
+ "0x%016zx failed to free private data for "
"%s (ignored)\n",
- (unsigned long)(path->conv.u.app_func), path->name);
+ (size_t)path->conv.u.app_func, path->name);
} /* end if */
#endif
H5E_clear_stack(NULL); /*ignore the error*/
@@ -1518,9 +1518,9 @@ H5T_top_term_package(void)
if (H5DEBUG(T)) {
HDfprintf(H5DEBUG(T),
"H5T: conversion function "
- "0x%08lx failed to free private data for "
+ "0x%016zx failed to free private data for "
"%s (ignored)\n",
- (unsigned long)(path->conv.u.lib_func), path->name);
+ (size_t)path->conv.u.lib_func, path->name);
} /* end if */
#endif
H5E_clear_stack(NULL); /*ignore the error*/
@@ -2632,9 +2632,9 @@ H5T__register(H5T_pers_t pers, const char *name, H5T_t *src, H5T_t *dst, H5T_con
#ifdef H5T_DEBUG
if (H5DEBUG(T))
HDfprintf(H5DEBUG(T),
- "H5T: conversion function 0x%08lx "
+ "H5T: conversion function 0x%016zx "
"failed to free private data for %s (ignored)\n",
- (unsigned long)(old_path->conv.u.app_func), old_path->name);
+ (size_t)old_path->conv.u.app_func, old_path->name);
#endif
} /* end if */
} /* end if */
@@ -2643,9 +2643,9 @@ H5T__register(H5T_pers_t pers, const char *name, H5T_t *src, H5T_t *dst, H5T_con
#ifdef H5T_DEBUG
if (H5DEBUG(T))
HDfprintf(H5DEBUG(T),
- "H5T: conversion function 0x%08lx "
+ "H5T: conversion function 0x%016zx "
"failed to free private data for %s (ignored)\n",
- (unsigned long)(old_path->conv.u.lib_func), old_path->name);
+ (size_t)old_path->conv.u.lib_func, old_path->name);
#endif
} /* end if */
(void)H5T_close_real(old_path->src);
@@ -2812,9 +2812,9 @@ H5T__unregister(H5T_pers_t pers, const char *name, H5T_t *src, H5T_t *dst, H5T_c
#ifdef H5T_DEBUG
if (H5DEBUG(T))
HDfprintf(H5DEBUG(T),
- "H5T: conversion function 0x%08lx failed "
+ "H5T: conversion function 0x%016zx failed "
"to free private data for %s (ignored)\n",
- (unsigned long)(path->conv.u.app_func), path->name);
+ (size_t)path->conv.u.app_func, path->name);
#endif
} /* end if */
} /* end if */
@@ -2823,9 +2823,9 @@ H5T__unregister(H5T_pers_t pers, const char *name, H5T_t *src, H5T_t *dst, H5T_c
#ifdef H5T_DEBUG
if (H5DEBUG(T))
HDfprintf(H5DEBUG(T),
- "H5T: conversion function 0x%08lx failed "
+ "H5T: conversion function 0x%016zx failed "
"to free private data for %s (ignored)\n",
- (unsigned long)(path->conv.u.lib_func), path->name);
+ (size_t)path->conv.u.lib_func, path->name);
#endif
} /* end if */
(void)H5T_close_real(path->src);
@@ -5220,8 +5220,8 @@ H5T__path_find_real(const H5T_t *src, const H5T_t *dst, const char *name, H5T_co
(size_t)0, NULL, NULL, H5CX_get_dxpl()) < 0) {
#ifdef H5T_DEBUG
if (H5DEBUG(T))
- HDfprintf(H5DEBUG(T), "H5T: conversion function 0x%08lx free failed for %s (ignored)\n",
- (unsigned long)(path->conv.u.app_func), path->name);
+ HDfprintf(H5DEBUG(T), "H5T: conversion function 0x%016zx free failed for %s (ignored)\n",
+ (size_t)path->conv.u.app_func, path->name);
#endif
H5E_clear_stack(NULL); /*ignore the failure*/
} /* end if */
@@ -5230,8 +5230,8 @@ H5T__path_find_real(const H5T_t *src, const H5T_t *dst, const char *name, H5T_co
(size_t)0, NULL, NULL) < 0) {
#ifdef H5T_DEBUG
if (H5DEBUG(T))
- HDfprintf(H5DEBUG(T), "H5T: conversion function 0x%08lx free failed for %s (ignored)\n",
- (unsigned long)(path->conv.u.lib_func), path->name);
+ HDfprintf(H5DEBUG(T), "H5T: conversion function 0x%016zx free failed for %s (ignored)\n",
+ (size_t)path->conv.u.lib_func, path->name);
#endif
H5E_clear_stack(NULL); /*ignore the failure*/
} /* end if */
diff --git a/src/H5Tconv.c b/src/H5Tconv.c
index 93ca59f..8118eb0 100644
--- a/src/H5Tconv.c
+++ b/src/H5Tconv.c
@@ -887,7 +887,17 @@ done:
/* Macro defining action on source data which needs to be aligned (before main action) */
#define H5T_CONV_LOOP_PRE_SALIGN(ST) \
{ \
- H5MM_memcpy(&src_aligned, src, sizeof(ST)); \
+ /* The uint8_t * cast is required to avoid tripping over undefined behavior. \
+ * \
+ * The typed pointer arrives via a void pointer, which may have any alignment. \
+ * We then cast it to a pointer to a type that is assumed to be aligned, which \
+ * is undefined behavior (section 6.3.2.3 paragraph 7 of the C99 standard). \
+ * In the past this hasn't caused many problems, but in some cases (e.g. \
+ * converting long doubles on macOS), an optimizing compiler might do the \
+ * wrong thing (in the macOS case, the conversion uses SSE, which has stricter \
+ * requirements about alignment). \
+ */ \
+ H5MM_memcpy(&src_aligned, (const uint8_t *)src, sizeof(ST)); \
}
/* Macro defining action on source data which doesn't need to be aligned (before main action) */
@@ -919,7 +929,17 @@ done:
/* Macro defining action on destination data which needs to be aligned (after main action) */
#define H5T_CONV_LOOP_POST_DALIGN(DT) \
{ \
- H5MM_memcpy(dst, &dst_aligned, sizeof(DT)); \
+ /* The uint8_t * cast is required to avoid tripping over undefined behavior. \
+ * \
+ * The typed pointer arrives via a void pointer, which may have any alignment. \
+ * We then cast it to a pointer to a type that is assumed to be aligned, which \
+ * is undefined behavior (section 6.3.2.3 paragraph 7 of the C99 standard). \
+ * In the past this hasn't caused many problems, but in some cases (e.g. \
+ * converting long doubles on macOS), an optimizing compiler might do the \
+ * wrong thing (in the macOS case, the conversion uses SSE, which has stricter \
+ * requirements about alignment). \
+ */ \
+ H5MM_memcpy((uint8_t *)dst, &dst_aligned, sizeof(DT)); \
}
/* Macro defining action on destination data which doesn't need to be aligned (after main action) */
diff --git a/src/H5system.c b/src/H5system.c
index ecaa0f6..8991f6a 100644
--- a/src/H5system.c
+++ b/src/H5system.c
@@ -983,6 +983,7 @@ Wstrcasestr_wrap(const char *haystack, const char *needle)
else
return StrStrIA(haystack, needle);
}
+
#endif /* H5_HAVE_WIN32_API */
/* dirname() and basename() are not easily ported to Windows and basename