summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2014-02-20 21:29:26 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2014-02-20 21:29:26 (GMT)
commit1e36b5a348415501aa8eb992fd57c09d834900cd (patch)
tree9a423be6cbe38eed62268779703258972fb94191 /tools
parentb30e37ea78a85c9a2e3abda7fddaabb636935b1c (diff)
downloadhdf5-1e36b5a348415501aa8eb992fd57c09d834900cd.zip
hdf5-1e36b5a348415501aa8eb992fd57c09d834900cd.tar.gz
hdf5-1e36b5a348415501aa8eb992fd57c09d834900cd.tar.bz2
[svn-r24726] Description:
Revert some earlier usage of strncpy, which was incorrect. Bring Coverity changes from branch back to trunk: r20821: Use HDstrncpy. --gh (Fixed already, with strdup) r20822: (Not merged, incorrect use of HDstrncpy()) r20823: (Not merged, incorrect use of HDstrncpy()) r20824: Maintenance: Bug fix: addressed CID 666. Value stored at *expression_len should be used in the call to HD5packFstring to avoid overflow (and unnecessary arithmetic calculation and casting) r20825: Issue 642: Added check for error and handler with print to stderr and exit. r20826: Undo revision 20818, as that issue has already been fixed in the 1.8 branch and trunk (but not coverity branch) r20827: (Not merged, incorrect use of HDstrncpy()) r20828: Use HDstrncpy. --gh (Corrected use of strncpy()) r20829: Check return of H5Lget_val(print_udata->fid, path, targbuf, linfo->u.val_size + 1, H5P_DEFAULT) and if error set trgbuf[0] to 0. Check if H5Lunpack_elink_val(targbuf, linfo->u.val_size, NULL, &filename, &objname) was successful and allow print. Otherwise filename and objname are not created. (init those to NULL) r20830: resolved coverity issues 939, 940, 941, 944, and 947. all were complaints about use of sprintf, and in all cases, the buffers used were large enough for all eventualities. Resolved issue by replacing calls to sprintf with calls to snprintf. r20831: Maintenance: Addressed CID 852 Replaced sprintf with snprintf r20832: Purpose: Fix valgrind issues with hl/examples/ex_image2 Description: Modified hl/examples/ex_image2 to free global "gbuf" before exit. Tested on: Mac OSX/64 10.9.1 (amaon) w/C++, FORTRAN & Threadsafety (too minor to require h5committest)
Diffstat (limited to 'tools')
-rw-r--r--tools/h5dump/h5dump_xml.c110
-rw-r--r--tools/lib/h5trav.c36
-rw-r--r--tools/misc/h5debug.c5
3 files changed, 83 insertions, 68 deletions
diff --git a/tools/h5dump/h5dump_xml.c b/tools/h5dump/h5dump_xml.c
index 03e1254..b94879c 100644
--- a/tools/h5dump/h5dump_xml.c
+++ b/tools/h5dump/h5dump_xml.c
@@ -644,6 +644,7 @@ xml_escape_the_name(const char *str)
const char *cp;
char *ncp;
char *rcp;
+ size_t ncp_len;
if (!str)
return NULL;
@@ -653,21 +654,16 @@ xml_escape_the_name(const char *str)
extra = 0;
for (i = 0; i < len; i++) {
- if (*cp == '\"') {
+ if (*cp == '\"')
extra += (HDstrlen(quote) - 1);
- }
- else if (*cp == '\'') {
+ else if (*cp == '\'')
extra += (HDstrlen(apos) - 1);
- }
- else if (*cp == '<') {
+ else if (*cp == '<')
extra += (HDstrlen(lt) - 1);
- }
- else if (*cp == '>') {
+ else if (*cp == '>')
extra += (HDstrlen(gt) - 1);
- }
- else if (*cp == '&') {
+ else if (*cp == '&')
extra += (HDstrlen(amp) - 1);
- }
cp++;
}
@@ -676,40 +672,43 @@ xml_escape_the_name(const char *str)
return HDstrdup(str);
cp = str;
- rcp = ncp = (char *)HDmalloc(len + extra + 1);
+ ncp_len = len + extra + 1;
+ rcp = ncp = (char *)HDmalloc(ncp_len);
if (!ncp)
return NULL; /* ?? */
for (i = 0; i < len; i++) {
+ size_t esc_len;
+
+ HDassert(ncp_len);
if (*cp == '\'') {
- HDstrncpy(ncp, apos, HDstrlen(apos));
- ncp += HDstrlen(apos);
- cp++;
+ HDstrncpy(ncp, apos, ncp_len);
+ esc_len = HDstrlen(apos);
}
else if (*cp == '<') {
- HDstrncpy(ncp, lt, HDstrlen(lt));
- ncp += HDstrlen(lt);
- cp++;
+ HDstrncpy(ncp, lt, ncp_len);
+ esc_len = HDstrlen(lt);
}
else if (*cp == '>') {
- HDstrncpy(ncp, gt, HDstrlen(gt));
- ncp += HDstrlen(gt);
- cp++;
+ HDstrncpy(ncp, gt, ncp_len);
+ esc_len = HDstrlen(gt);
}
else if (*cp == '\"') {
- HDstrncpy(ncp, quote, HDstrlen(quote));
- ncp += HDstrlen(quote);
- cp++;
+ HDstrncpy(ncp, quote, ncp_len);
+ esc_len = HDstrlen(quote);
}
else if (*cp == '&') {
- HDstrncpy(ncp, amp, HDstrlen(amp));
- ncp += HDstrlen(amp);
- cp++;
+ HDstrncpy(ncp, amp, ncp_len);
+ esc_len = HDstrlen(amp);
}
else {
- *ncp++ = *cp++;
+ *ncp = *cp;
+ esc_len = 1;
}
+ ncp += esc_len;
+ ncp_len -= esc_len;
+ cp++;
}
*ncp = '\0';
@@ -739,6 +738,7 @@ xml_escape_the_string(const char *str, int slen)
const char *cp;
char *ncp;
char *rcp;
+ size_t ncp_len;
if (!str)
return NULL;
@@ -753,65 +753,65 @@ xml_escape_the_string(const char *str, int slen)
extra = 0;
for (i = 0; i < len; i++) {
- if (*cp == '\\') {
+ if (*cp == '\\')
extra++;
- }
- else if (*cp == '\"') {
+ else if (*cp == '\"')
extra++;
- }
- else if (*cp == '\'') {
+ else if (*cp == '\'')
extra += (HDstrlen(apos) - 1);
- }
- else if (*cp == '<') {
+ else if (*cp == '<')
extra += (HDstrlen(lt) - 1);
- }
- else if (*cp == '>') {
+ else if (*cp == '>')
extra += (HDstrlen(gt) - 1);
- }
- else if (*cp == '&') {
+ else if (*cp == '&')
extra += (HDstrlen(amp) - 1);
- }
cp++;
}
cp = str;
- rcp = ncp = (char *) HDcalloc((len + extra + 1), sizeof(char));
+ ncp_len = len + extra + 1;
+ rcp = ncp = (char *) HDcalloc(ncp_len, sizeof(char));
if (ncp == NULL)
return NULL; /* ?? */
for (i = 0; i < len; i++) {
+ size_t esc_len;
+
+ HDassert(ncp_len);
if (*cp == '\\') {
*ncp++ = '\\';
- *ncp++ = *cp++;
+ *ncp = *cp;
+ esc_len = 1;
}
else if (*cp == '\"') {
*ncp++ = '\\';
- *ncp++ = *cp++;
+ *ncp = *cp;
+ esc_len = 1;
}
else if (*cp == '\'') {
- HDstrncpy(ncp, apos, HDstrlen(apos));
- ncp += HDstrlen(apos);
- cp++;
+ HDstrncpy(ncp, apos, ncp_len);
+ esc_len = HDstrlen(apos);
}
else if (*cp == '<') {
- HDstrncpy(ncp, lt, HDstrlen(lt));
- ncp += HDstrlen(lt);
- cp++;
+ HDstrncpy(ncp, lt, ncp_len);
+ esc_len = HDstrlen(lt);
}
else if (*cp == '>') {
- HDstrncpy(ncp, gt, HDstrlen(gt));
- ncp += HDstrlen(gt);
- cp++;
+ HDstrncpy(ncp, gt, ncp_len);
+ esc_len = HDstrlen(gt);
}
else if (*cp == '&') {
- HDstrncpy(ncp, amp, HDstrlen(amp));
- ncp += HDstrlen(amp);
- cp++;
+ HDstrncpy(ncp, amp, ncp_len);
+ esc_len = HDstrlen(amp);
}
else {
- *ncp++ = *cp++;
+ *ncp = *cp;
+ esc_len = 1;
}
+ ncp += esc_len;
+ ncp_len -= esc_len;
+ cp++;
}
*ncp = '\0';
diff --git a/tools/lib/h5trav.c b/tools/lib/h5trav.c
index a475ded..fca3096 100644
--- a/tools/lib/h5trav.c
+++ b/tools/lib/h5trav.c
@@ -49,7 +49,9 @@ typedef struct {
} trav_print_udata_t;
/* format for hsize_t */
+#ifdef H5TRAV_PRINT_SPACE
#define HSIZE_T_FORMAT "%" H5_PRINTF_LL_WIDTH "u"
+#endif /* H5TRAV_PRINT_SPACE */
/*-------------------------------------------------------------------------
* local functions
@@ -680,11 +682,11 @@ h5trav_getindext(const char *name, const trav_table_t *table)
for(i = 0; i < table->nobjs; i++) {
/* Check for object name having full path (with leading '/') */
if(HDstrcmp(name, table->objs[i].name) == 0)
- return(i);
+ return((int)i);
/* Check for object name without leading '/' */
if(HDstrcmp(name, table->objs[i].name + 1) == 0)
- return(i);
+ return((int)i);
/* search also in the list of links */
if(table->objs[i].nlinks) {
@@ -693,11 +695,11 @@ h5trav_getindext(const char *name, const trav_table_t *table)
for ( j=0; j<table->objs[i].nlinks; j++) {
/* Check for object name having full path (with leading '/') */
if(HDstrcmp(name, table->objs[i].links[j].new_name) == 0)
- return(i);
+ return((int)i);
/* Check for object name without leading '/' */
if(HDstrcmp(name, table->objs[i].links[j].new_name + 1) == 0)
- return(i);
+ return((int)i);
} /* end for */
} /* end if */
} /* end for */
@@ -807,7 +809,7 @@ void trav_table_addflags(unsigned *flags,
h5trav_type_t type,
trav_table_t *table)
{
- unsigned int new_obj;
+ size_t new_obj;
if(table->nobjs == table->size) {
table->size = MAX(1, table->size * 2);
@@ -995,6 +997,8 @@ trav_print_visit_obj(const char *path, const H5O_info_t *oinfo,
printf(" %-10s %s", "datatype", path);
break;
+ case H5O_TYPE_UNKNOWN:
+ case H5O_TYPE_NTYPES:
default:
printf(" %-10s %s", "unknown object type", path);
break;
@@ -1005,7 +1009,7 @@ trav_print_visit_obj(const char *path, const H5O_info_t *oinfo,
/* Finish printing line about object */
printf("\n");
if(trav_verbosity > 0)
- H5Aiterate_by_name(print_udata->fid, path, trav_index_by, trav_index_order, NULL, trav_attr, path, H5P_DEFAULT);
+ H5Aiterate_by_name(print_udata->fid, path, trav_index_by, trav_index_order, NULL, trav_attr, (void *)path, H5P_DEFAULT);
}
else
/* Print the link's original name */
@@ -1040,7 +1044,8 @@ trav_print_visit_lnk(const char *path, const H5L_info_t *linfo, void *udata)
char *targbuf = (char*)HDmalloc(linfo->u.val_size + 1);
HDassert(targbuf);
- H5Lget_val(print_udata->fid, path, targbuf, linfo->u.val_size + 1, H5P_DEFAULT);
+ if(H5Lget_val(print_udata->fid, path, targbuf, linfo->u.val_size + 1, H5P_DEFAULT) < 0)
+ targbuf[0] = 0;
printf(" %-10s %s -> %s\n", "link", path, targbuf);
HDfree(targbuf);
} /* end if */
@@ -1051,21 +1056,28 @@ trav_print_visit_lnk(const char *path, const H5L_info_t *linfo, void *udata)
case H5L_TYPE_EXTERNAL:
if(linfo->u.val_size > 0) {
char *targbuf;
- const char *filename;
- const char *objname;
+ const char *filename = NULL;
+ const char *objname = NULL;
targbuf = (char*)HDmalloc(linfo->u.val_size + 1);
HDassert(targbuf);
- H5Lget_val(print_udata->fid, path, targbuf, linfo->u.val_size + 1, H5P_DEFAULT);
- H5Lunpack_elink_val(targbuf, linfo->u.val_size, NULL, &filename, &objname);
- printf(" %-10s %s -> %s %s\n", "ext link", path, filename, objname);
+ if(H5Lget_val(print_udata->fid, path, targbuf, linfo->u.val_size + 1, H5P_DEFAULT) < 0)
+ targbuf[0] = 0;
+ if(H5Lunpack_elink_val(targbuf, linfo->u.val_size, NULL, &filename, &objname) >= 0)
+ printf(" %-10s %s -> %s %s\n", "ext link", path, filename, objname);
HDfree(targbuf);
} /* end if */
else
printf(" %-10s %s ->\n", "ext link", path);
break;
+ case H5L_TYPE_HARD:
+ /* Should be handled elsewhere */
+ return(-1);
+
+ case H5L_TYPE_ERROR:
+ case H5L_TYPE_MAX:
default:
printf(" %-10s %s -> ???\n", "unknown type of UD link", path);
break;
diff --git a/tools/misc/h5debug.c b/tools/misc/h5debug.c
index 9df49cf..617e614 100644
--- a/tools/misc/h5debug.c
+++ b/tools/misc/h5debug.c
@@ -248,7 +248,10 @@ main(int argc, char *argv[])
HDexit(1);
} /* end if */
if(HDstrchr(argv[1], '%'))
- H5Pset_fapl_family (fapl, (hsize_t)0, H5P_DEFAULT);
+ if(H5Pset_fapl_family (fapl, (hsize_t)0, H5P_DEFAULT) < 0) {
+ fprintf(stderr, "cannot set file access property list\n");
+ HDexit(1);
+ }
if((fid = H5Fopen(argv[1], H5F_ACC_RDONLY, fapl)) < 0) {
HDfprintf(stderr, "cannot open file\n");
HDexit(1);