summaryrefslogtreecommitdiffstats
path: root/tools/lib/h5tools_utils.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2010-07-29 19:07:26 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2010-07-29 19:07:26 (GMT)
commit7fe87a24722f991ffc030782cd42d24df00dbace (patch)
tree7d466f911a952916b99e2c86e83202d0e07cffaa /tools/lib/h5tools_utils.c
parent178b80b679b874d99287b28898e242533721ea67 (diff)
downloadhdf5-7fe87a24722f991ffc030782cd42d24df00dbace.zip
hdf5-7fe87a24722f991ffc030782cd42d24df00dbace.tar.gz
hdf5-7fe87a24722f991ffc030782cd42d24df00dbace.tar.bz2
[svn-r19153] Description:
Bring changes on Coverity branch back to trunk: r19040: Fixed coverity #440 - NULL check after dereference. We moved the NULL check up into the IF block and changed it to assertion. r19041: Maintenance: Addressed Coverity issues 441 and 449 by initializing proper variables r19042: In function H5O_chunk_protect (H5Ochunk.c): - Initialize H5O_chunk_proxy_t pointers chk_proxy and ret_value. - Free chk_proxy on error. r19043: Addressed coverity issues 442 - 448 by initializing pointers to NULL. Tested on: Mac OS X/32 10.6.4 (amazon) w/debug & production (Too minor to require h5committest)
Diffstat (limited to 'tools/lib/h5tools_utils.c')
-rw-r--r--tools/lib/h5tools_utils.c77
1 files changed, 34 insertions, 43 deletions
diff --git a/tools/lib/h5tools_utils.c b/tools/lib/h5tools_utils.c
index 04d375d..b226bd7 100644
--- a/tools/lib/h5tools_utils.c
+++ b/tools/lib/h5tools_utils.c
@@ -338,11 +338,11 @@ print_version(const char *progname)
static void
init_table(table_t **tbl)
{
- table_t *table = HDmalloc(sizeof(table_t));
+ table_t *table = (table_t *)HDmalloc(sizeof(table_t));
table->size = 20;
table->nobjs = 0;
- table->objs = HDmalloc(table->size * sizeof(obj_t));
+ table->objs = (obj_t *)HDmalloc(table->size * sizeof(obj_t));
*tbl = table;
}
@@ -653,63 +653,59 @@ tmpfile(void)
*
* Date: Feb 8, 2010
*-------------------------------------------------------------------------*/
-int H5tools_get_link_info(hid_t file_id, const char * linkpath, h5tool_link_info_t *link_info)
+int
+H5tools_get_link_info(hid_t file_id, const char * linkpath, h5tool_link_info_t *link_info)
{
- int ret = -1; /* init to fail */
htri_t l_ret;
H5O_info_t trg_oinfo;
- hid_t fapl;
+ hid_t fapl = H5P_DEFAULT;
hid_t lapl = H5P_DEFAULT;
+ int ret = -1; /* init to fail */
/* init */
link_info->trg_type = H5O_TYPE_UNKNOWN;
/* check if link itself exist */
- if((H5Lexists(file_id, linkpath, H5P_DEFAULT) <= 0))
- {
- if(link_info->opt.msg_mode==1)
+ if(H5Lexists(file_id, linkpath, H5P_DEFAULT) <= 0) {
+ if(link_info->opt.msg_mode == 1)
parallel_print("Warning: link <%s> doesn't exist \n",linkpath);
goto out;
- }
+ } /* end if */
/* get info from link */
- if(H5Lget_info(file_id, linkpath, &(link_info->linfo), H5P_DEFAULT) < 0)
- {
- if(link_info->opt.msg_mode==1)
+ if(H5Lget_info(file_id, linkpath, &(link_info->linfo), H5P_DEFAULT) < 0) {
+ if(link_info->opt.msg_mode == 1)
parallel_print("Warning: unable to get link info from <%s>\n",linkpath);
goto out;
- }
+ } /* end if */
/* given path is hard link (object) */
- if (link_info->linfo.type == H5L_TYPE_HARD)
- {
+ if(link_info->linfo.type == H5L_TYPE_HARD) {
ret = 2;
goto out;
- }
+ } /* end if */
/* trg_path must be freed out of this function when finished using */
link_info->trg_path = (char*)HDcalloc(link_info->linfo.u.val_size, sizeof(char));
HDassert(link_info->trg_path);
/* get link value */
- if(H5Lget_val(file_id, linkpath, link_info->trg_path, link_info->linfo.u.val_size, H5P_DEFAULT) < 0)
- {
- if(link_info->opt.msg_mode==1)
+ if(H5Lget_val(file_id, linkpath, link_info->trg_path, link_info->linfo.u.val_size, H5P_DEFAULT) < 0) {
+ if(link_info->opt.msg_mode == 1)
parallel_print("Warning: unable to get link value from <%s>\n",linkpath);
goto out;
- }
+ } /* end if */
/*-----------------------------------------------------
* if link type is external link use different lapl to
* follow object in other file
*/
- if (link_info->linfo.type == H5L_TYPE_EXTERNAL)
- {
+ if(link_info->linfo.type == H5L_TYPE_EXTERNAL) {
fapl = H5Pcreate(H5P_FILE_ACCESS);
H5Pset_fapl_sec2(fapl);
lapl = H5Pcreate(H5P_LINK_ACCESS);
H5Pset_elink_fapl(lapl, fapl);
- }
+ } /* end if */
/*--------------------------------------------------------------
* if link's target object exist, get type
@@ -718,47 +714,42 @@ int H5tools_get_link_info(hid_t file_id, const char * linkpath, h5tool_link_info
l_ret = H5Oexists_by_name(file_id, linkpath, lapl);
/* detect dangling link */
- if(l_ret == FALSE)
- {
- ret = 0;
- goto out;
- }
+ if(l_ret == FALSE) {
+ ret = 0;
+ goto out;
+ } /* end if */
/* function failed */
- else if (l_ret < 0)
- {
+ else if(l_ret < 0)
goto out;
- }
/* get target object info */
- if(H5Oget_info_by_name(file_id, linkpath, &trg_oinfo, lapl) < 0)
- {
- if(link_info->opt.msg_mode==1)
+ if(H5Oget_info_by_name(file_id, linkpath, &trg_oinfo, lapl) < 0) {
+ if(link_info->opt.msg_mode == 1)
parallel_print("Warning: unable to get object information for <%s>\n", linkpath);
goto out;
- }
+ } /* end if */
/* check unknown type */
- if (trg_oinfo.type < H5O_TYPE_GROUP || trg_oinfo.type >=H5O_TYPE_NTYPES)
- {
- if(link_info->opt.msg_mode==1)
+ if(trg_oinfo.type < H5O_TYPE_GROUP || trg_oinfo.type >=H5O_TYPE_NTYPES) {
+ if(link_info->opt.msg_mode == 1)
parallel_print("Warning: target object of <%s> is unknown type\n", linkpath);
goto out;
- }
+ } /* end if */
/* set target obj type to return */
link_info->trg_type = trg_oinfo.type;
/* succeed */
ret = 1;
+
out:
- if (link_info->linfo.type == H5L_TYPE_EXTERNAL)
- {
+ if(fapl != H5P_DEFAULT)
H5Pclose(fapl);
+ if(lapl != H5P_DEFAULT)
H5Pclose(lapl);
- }
return ret;
-}
+} /* end H5tools_get_link_info() */
/*-------------------------------------------------------------------------
* Audience: Public