diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2014-03-16 04:44:13 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2014-03-16 04:44:13 (GMT) |
commit | 164b4c75341ee4aa31dcd47c189e415a36ae35e2 (patch) | |
tree | 121120c9d2df2d601730e4c371afbf5f82004f92 /tools/lib | |
parent | 288c7760a4a55d56df7a9019a8522625e305b9b7 (diff) | |
download | hdf5-164b4c75341ee4aa31dcd47c189e415a36ae35e2.zip hdf5-164b4c75341ee4aa31dcd47c189e415a36ae35e2.tar.gz hdf5-164b4c75341ee4aa31dcd47c189e415a36ae35e2.tar.bz2 |
[svn-r24804] Description:
Brought changes from Coverity branch back to trunk, and cleaned up misc.
other warnings & formatting issues:
r20833:
Fixed Coverity 667 and 668 with real integer overflow tests this time.
r20834:
Use HDstrncpy and HDstrncat. --gh
r20835:
Change to use strncpy - use base_len + 1 for line 156, use HDstrlen(path) + 1 for line 159
r20836:
Fixed coverity 585 by casting output of fgetc() to a char.
r20837:
Changed sprintf calls to snprintf with size 1 less than the allocated buffer to address coverity issue #967.
Tested on:
Mac OSX/64 10.9.2 (amazon) w/C++, FORTRAN & parallel
(too minor to require h5committest)
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/h5diff.c | 2 | ||||
-rw-r--r-- | tools/lib/h5trav.c | 102 | ||||
-rw-r--r-- | tools/lib/h5trav.h | 12 |
3 files changed, 47 insertions, 69 deletions
diff --git a/tools/lib/h5diff.c b/tools/lib/h5diff.c index ab21bfd..884a85d 100644 --- a/tools/lib/h5diff.c +++ b/tools/lib/h5diff.c @@ -1096,7 +1096,6 @@ hsize_t diff_match(hid_t file1_id, const char *grp1, trav_info_t *info1, char * grp2_path = ""; char * obj1_fullpath = NULL; char * obj2_fullpath = NULL; - h5trav_type_t objtype; diff_args_t argdata; size_t idx1 = 0; size_t idx2 = 0; @@ -1163,7 +1162,6 @@ hsize_t diff_match(hid_t file1_id, const char *grp1, trav_info_t *info1, { if( table->objs[i].flags[0] && table->objs[i].flags[1]) { - objtype = table->objs[i].type; /* make full path for obj1 */ obj1_fullpath = (char*)HDcalloc (HDstrlen(grp1_path) + strlen (table->objs[i].name) + 1, sizeof (char)); HDstrcpy(obj1_fullpath, grp1_path); diff --git a/tools/lib/h5trav.c b/tools/lib/h5trav.c index fca3096..d0a4a76 100644 --- a/tools/lib/h5trav.c +++ b/tools/lib/h5trav.c @@ -21,13 +21,15 @@ * local typedefs *------------------------------------------------------------------------- */ +typedef struct trav_addr_path_t { + haddr_t addr; + char *path; +} trav_addr_path_t; + typedef struct trav_addr_t { size_t nalloc; size_t nused; - struct { - haddr_t addr; - char *path; - } *objs; + trav_addr_path_t *objs; } trav_addr_t; typedef struct { @@ -132,7 +134,7 @@ trav_addr_add(trav_addr_t *visited, haddr_t addr, const char *path) /* Allocate space if necessary */ if(visited->nused == visited->nalloc) { visited->nalloc = MAX(1, visited->nalloc * 2);; - visited->objs = HDrealloc(visited->objs, visited->nalloc * sizeof(visited->objs[0])); + visited->objs = (trav_addr_path_t *)HDrealloc(visited->objs, visited->nalloc * sizeof(trav_addr_path_t)); } /* end if */ /* Append it */ @@ -194,14 +196,15 @@ traverse_cb(hid_t loc_id, const char *path, const H5L_info_t *linfo, /* Create the full path name for the link */ if(udata->is_absolute) { size_t base_len = HDstrlen(udata->base_grp_name); - size_t add_slash = base_len ? ((udata->base_grp_name)[base_len-1] != '/') : 1; + size_t add_slash = base_len ? ((udata->base_grp_name)[base_len - 1] != '/') : 1; + size_t new_name_len = base_len + add_slash + HDstrlen(path) + 1; - if(NULL == (new_name = (char*)HDmalloc(base_len + add_slash + HDstrlen(path) + 1))) + if(NULL == (new_name = (char*)HDmalloc(new_name_len))) return(H5_ITER_ERROR); - HDstrcpy(new_name, udata->base_grp_name); - if (add_slash) - new_name[base_len] = '/'; - HDstrcpy(new_name + base_len + add_slash, path); + if(add_slash) + HDsnprintf(new_name, new_name_len, "%s/%s", udata->base_grp_name, path); + else + HDsnprintf(new_name, new_name_len, "%s%s", udata->base_grp_name, path); full_name = new_name; } /* end if */ else @@ -216,7 +219,7 @@ traverse_cb(hid_t loc_id, const char *path, const H5L_info_t *linfo, if(new_name) HDfree(new_name); return(H5_ITER_ERROR); - } + } /* end if */ /* If the object has multiple links, add it to the list of addresses * already visited, if it isn't there already @@ -231,7 +234,7 @@ traverse_cb(hid_t loc_id, const char *path, const H5L_info_t *linfo, if(new_name) HDfree(new_name); return(H5_ITER_ERROR); - } + } /* end if */ } /* end if */ else { /* Make 'visit link' callback */ @@ -240,7 +243,7 @@ traverse_cb(hid_t loc_id, const char *path, const H5L_info_t *linfo, if(new_name) HDfree(new_name); return(H5_ITER_ERROR); - } + } /* end if */ } /* end else */ if(new_name) @@ -730,7 +733,7 @@ trav_table_add(trav_table_t *table, if(table->nobjs == table->size) { table->size = MAX(1, table->size * 2); - table->objs = (trav_obj_t*)HDrealloc(table->objs, table->size * sizeof(trav_obj_t)); + table->objs = (trav_obj_t *)HDrealloc(table->objs, table->size * sizeof(trav_obj_t)); } /* end if */ new_obj = table->nobjs++; @@ -774,7 +777,7 @@ trav_table_addlink(trav_table_t *table, haddr_t objno, const char *path) /* allocate space if necessary */ if(table->objs[i].nlinks == (unsigned)table->objs[i].sizelinks) { table->objs[i].sizelinks = MAX(1, table->objs[i].sizelinks * 2); - table->objs[i].links = (trav_link_t*)HDrealloc(table->objs[i].links, table->objs[i].sizelinks * sizeof(trav_link_t)); + table->objs[i].links = (trav_link_t *)HDrealloc(table->objs[i].links, table->objs[i].sizelinks * sizeof(trav_link_t)); } /* end if */ /* insert it */ @@ -1168,31 +1171,21 @@ h5trav_visit(hid_t fid, const char *grp_name, hbool_t visit_start, * * Date: September 5, 2008 * - * Modified: - * Jonathan Kim - * - Moved from h5ls.c to share among tools. (Sep 16, 2010) - * - Renamed from elink_trav_add to symlink_visit_add for both soft and - * external links. (May 25, 2010) - * - Add type parameter to distingush between soft and external link for - * sure, which prevent from mixing up visited link when the target names - * are same between the soft and external link, as code marks with the - * target name. (May 25,2010) - * *------------------------------------------------------------------------- */ herr_t symlink_visit_add(symlink_trav_t *visited, H5L_type_t type, const char *file, const char *path) { size_t idx; /* Index of address to use */ - void *tmp_ptr; /* Allocate space if necessary */ - if(visited->nused == visited->nalloc) - { + if(visited->nused == visited->nalloc) { + void *tmp_ptr; + visited->nalloc = MAX(1, visited->nalloc * 2); - if(NULL == (tmp_ptr = HDrealloc(visited->objs, visited->nalloc * sizeof(visited->objs[0])))) + if(NULL == (tmp_ptr = HDrealloc(visited->objs, visited->nalloc * sizeof(symlink_trav_path_t)))) return -1; - visited->objs = tmp_ptr; + visited->objs = (symlink_trav_path_t *)tmp_ptr; } /* end if */ /* Append it */ @@ -1202,22 +1195,19 @@ symlink_visit_add(symlink_trav_t *visited, H5L_type_t type, const char *file, co visited->objs[idx].file = NULL; visited->objs[idx].path = NULL; - if (type == H5L_TYPE_EXTERNAL) - { - if(NULL == (visited->objs[idx].file = HDstrdup(file))) - { + if(type == H5L_TYPE_EXTERNAL) { + if(NULL == (visited->objs[idx].file = HDstrdup(file))) { visited->nused--; return -1; - } - } + } /* end if */ + } /* end if */ - if(NULL == (visited->objs[idx].path = HDstrdup(path))) - { + if(NULL == (visited->objs[idx].path = HDstrdup(path))) { visited->nused--; - if (visited->objs[idx].file) + if(visited->objs[idx].file) HDfree (visited->objs[idx].file); return -1; - } + } /* end if */ return 0; } /* end symlink_visit_add() */ @@ -1235,16 +1225,6 @@ symlink_visit_add(symlink_trav_t *visited, H5L_type_t type, const char *file, co * * Date: September 5, 2008 * - * Modified: - * Jonathan Kim - * - Moved from h5ls.c to share among tools. (Sep 16, 2010) - * - Renamed from elink_trav_visited to symlink_is_visited for both soft and - * external links. (May 25, 2010) - * - Add type parameter to distingush between soft and external link for - * sure, which prevent from mixing up visited link when the target names - * are same between the soft and external link, as code marks with the - * target name. (May 25,2010) - * *------------------------------------------------------------------------- */ hbool_t @@ -1253,21 +1233,19 @@ symlink_is_visited(symlink_trav_t *visited, H5L_type_t type, const char *file, c size_t u; /* Local index variable */ /* Look for symlink */ - for(u = 0; u < visited->nused; u++) - { + for(u = 0; u < visited->nused; u++) { /* Check for symlink values already in array */ /* check type and path pair to distingush between symbolic links */ - if ((visited->objs[u].type == type) && !HDstrcmp(visited->objs[u].path, path)) - { + if((visited->objs[u].type == type) && !HDstrcmp(visited->objs[u].path, path)) { /* if external link, file need to be matched as well */ - if (visited->objs[u].type == H5L_TYPE_EXTERNAL) - { - if (!HDstrcmp(visited->objs[u].file, file)) - return (TRUE); - } + if(visited->objs[u].type == H5L_TYPE_EXTERNAL) + if(!HDstrcmp(visited->objs[u].file, file)) + return(TRUE); + return (TRUE); - } - } + } /* end if */ + } /* end for */ + /* Didn't find symlink */ return(FALSE); } /* end symlink_is_visited() */ diff --git a/tools/lib/h5trav.h b/tools/lib/h5trav.h index 3548c6b..352a9e5 100644 --- a/tools/lib/h5trav.h +++ b/tools/lib/h5trav.h @@ -51,14 +51,16 @@ typedef enum { /* Struct to keep track of symbolic link targets visited. * Functions: symlink_visit_add() and symlink_is_visited() */ +typedef struct symlink_trav_path_t { + H5L_type_t type; + char *file; + char *path; +} symlink_trav_path_t; + typedef struct symlink_trav_t { size_t nalloc; size_t nused; - struct { - H5L_type_t type; - char *file; - char *path; - } *objs; + symlink_trav_path_t *objs; hbool_t dangle_link; } symlink_trav_t; |