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

OESS-168: Remove clang warnings. #1299

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
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
21 changes: 16 additions & 5 deletions src/H5Lint.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,10 @@ H5L__link_cb(H5G_loc_t *grp_loc /*in*/, const char *name, const H5O_link_t H5_AT

/* Set the link's name correctly */
/* Casting away const OK -QAK */
udata->lnk->name = (char *)name;

udata->lnk->name = strdup(name);
if (NULL == udata->lnk->name) {
HGOTO_ERROR(H5E_LINK, H5E_CANTINIT, FAIL, "out of memory")
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since these changes are in callbacks, it sort of seems like doing a strdup each time probably wouldn't be optimal. This seems like the kind of thing that needs to be fixed somewhere higher up where we correctly differentiate between when the link name should be const and non-const.

If we do go with this change though, the strdup calls should be changed to HDstrdup, or even better, HDstrndup.

Copy link
Member Author

Choose a reason for hiding this comment

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

HDstrndup() is not available in H5private.h.
strndup() is not available for MS VS C compiler.
Thus, I replaced strdup() with HDstrdup().

Copy link
Contributor

Choose a reason for hiding this comment

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

Since these changes are in callbacks, it sort of seems like doing a strdup each time probably wouldn't be optimal. This seems like the kind of thing that needs to be fixed somewhere higher up where we correctly differentiate between when the link name should be const and non-const.

Agree

/* Insert link into group */
if (H5G_obj_insert(grp_loc->oloc, name, udata->lnk, TRUE,
udata->ocrt_info ? udata->ocrt_info->obj_type : H5O_TYPE_UNKNOWN,
Expand Down Expand Up @@ -646,8 +648,13 @@ H5L__link_cb(H5G_loc_t *grp_loc /*in*/, const char *name, const H5O_link_t H5_AT
} /* end if */

done:

/* Check if an object was created */
if (obj_created) {
if (NULL != udata->lnk->name) {
HDfree(udata->lnk->name);
}

H5O_loc_t oloc; /* Object location for created object */

/* Set up object location */
Expand Down Expand Up @@ -675,7 +682,6 @@ H5L__link_cb(H5G_loc_t *grp_loc /*in*/, const char *name, const H5O_link_t H5_AT
/* Indicate that this callback didn't take ownership of the group *
* location for the object */
*own_loc = H5G_OWN_NONE;

FUNC_LEAVE_NOAPI(ret_value)
} /* end H5L__link_cb() */

Expand Down Expand Up @@ -1376,7 +1382,10 @@ H5L__move_dest_cb(H5G_loc_t *grp_loc /*in*/, const char *name, const H5O_link_t
/* Give the object its new name */
/* Casting away const okay -JML */
HDassert(udata->lnk->name == NULL);
udata->lnk->name = (char *)name;
udata->lnk->name = strdup(name);
if (NULL == udata->lnk->name) {
HGOTO_ERROR(H5E_LINK, H5E_CANTINIT, FAIL, "out of memory")
}

/* Insert the link into the group */
if (H5G_obj_insert(grp_loc->oloc, name, udata->lnk, TRUE, H5O_TYPE_UNKNOWN, NULL) < 0)
Expand Down Expand Up @@ -1443,8 +1452,10 @@ H5L__move_dest_cb(H5G_loc_t *grp_loc /*in*/, const char *name, const H5O_link_t

/* Reset the "name" field in udata->lnk because it is owned by traverse()
* and must not be manipulated after traverse closes */
if (NULL != udata->lnk->name) {
HDfree(udata->lnk->name);
}
udata->lnk->name = NULL;

FUNC_LEAVE_NOAPI(ret_value)
} /* end H5L__move_dest_cb() */

Expand Down