Fix misc. warnings from GCC when compiling with -fsanitize=undefined (#3787)

This commit is contained in:
jhendersonHDF 2023-11-01 08:16:33 -05:00 committed by GitHub
parent a654b2c1c5
commit 562c53c44a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 7 deletions

View File

@ -911,7 +911,8 @@ H5D__mpio_get_no_coll_cause_strings(char *local_cause, size_t local_cause_len, c
case H5D_MPIO_COLLECTIVE:
case H5D_MPIO_NO_COLLECTIVE_MAX_CAUSE:
default:
assert(0 && "invalid no collective cause reason");
cause_str = "invalid or unknown no collective cause reason";
assert(0 && "invalid or unknown no collective cause reason");
break;
}

View File

@ -1427,7 +1427,8 @@ H5FD__family_delete(const char *filename, hid_t fapl_id)
FUNC_ENTER_PACKAGE
assert(filename);
if (!filename)
HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, FAIL, "invalid filename pointer");
/* Get the driver info (for the member fapl)
* The family_open call accepts H5P_DEFAULT, so we'll accept that here, too.

View File

@ -545,7 +545,7 @@ H5FD__log_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr)
#endif /* H5_HAVE_WIN32_API */
/* Retain a copy of the name used to open the file, for possible error reporting */
strncpy(file->filename, name, sizeof(file->filename));
strncpy(file->filename, name, sizeof(file->filename) - 1);
file->filename[sizeof(file->filename) - 1] = '\0';
/* Get the flags for logging */

View File

@ -368,7 +368,7 @@ H5FD__sec2_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr
}
/* Retain a copy of the name used to open the file, for possible error reporting */
strncpy(file->filename, name, sizeof(file->filename));
strncpy(file->filename, name, sizeof(file->filename) - 1);
file->filename[sizeof(file->filename) - 1] = '\0';
/* Check for non-default FAPL */

View File

@ -2501,7 +2501,7 @@ H5T__register(H5T_pers_t pers, const char *name, H5T_t *src, H5T_t *dst, H5T_con
H5T_g.asoft = na;
H5T_g.soft = x;
} /* end if */
strncpy(H5T_g.soft[H5T_g.nsoft].name, name, (size_t)H5T_NAMELEN);
strncpy(H5T_g.soft[H5T_g.nsoft].name, name, (size_t)H5T_NAMELEN - 1);
H5T_g.soft[H5T_g.nsoft].name[H5T_NAMELEN - 1] = '\0';
H5T_g.soft[H5T_g.nsoft].src = src->shared->type;
H5T_g.soft[H5T_g.nsoft].dst = dst->shared->type;
@ -2550,7 +2550,7 @@ H5T__register(H5T_pers_t pers, const char *name, H5T_t *src, H5T_t *dst, H5T_con
/* Create a new conversion path */
if (NULL == (new_path = H5FL_CALLOC(H5T_path_t)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
strncpy(new_path->name, name, (size_t)H5T_NAMELEN);
strncpy(new_path->name, name, (size_t)H5T_NAMELEN - 1);
new_path->name[H5T_NAMELEN - 1] = '\0';
if (NULL == (new_path->src = H5T_copy(old_path->src, H5T_COPY_ALL)) ||
NULL == (new_path->dst = H5T_copy(old_path->dst, H5T_COPY_ALL)))
@ -4953,7 +4953,7 @@ H5T__path_find_real(const H5T_t *src, const H5T_t *dst, const char *name, H5T_co
if (NULL == (path = H5FL_CALLOC(H5T_path_t)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for type conversion path");
if (name && *name) {
strncpy(path->name, name, (size_t)H5T_NAMELEN);
strncpy(path->name, name, (size_t)H5T_NAMELEN - 1);
path->name[H5T_NAMELEN - 1] = '\0';
} /* end if */
else

View File

@ -227,6 +227,10 @@ main(int argc, char *argv[])
if (argno >= argc)
usage(prog_name);
src_gen_name = argv[argno++];
if (!src_gen_name) {
fprintf(stderr, "invalid source file name pointer");
exit(EXIT_FAILURE);
}
snprintf(src_name, NAMELEN, src_gen_name, src_membno);
src_is_family = strcmp(src_name, src_gen_name);
@ -249,6 +253,10 @@ main(int argc, char *argv[])
if (argno >= argc)
usage(prog_name);
dst_gen_name = argv[argno++];
if (!dst_gen_name) {
fprintf(stderr, "invalid destination file name pointer");
exit(EXIT_FAILURE);
}
snprintf(dst_name, NAMELEN, dst_gen_name, dst_membno);
dst_is_family = strcmp(dst_name, dst_gen_name);