Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/H5Dmpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/H5FDfamily.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/H5FDlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/H5FDsec2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
6 changes: 3 additions & 3 deletions src/H5T.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions tools/src/misc/h5repart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though we are just exiting anyway, valgrind is going to complain we leak the name memory (allocated above) if we ever thoroughly test the command-ilne options options.

snprintf(src_name, NAMELEN, src_gen_name, src_membno);
src_is_family = strcmp(src_name, src_gen_name);

Expand All @@ -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);

Expand Down