diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/h5dump/h5dump_xml.c | 110 | ||||
-rw-r--r-- | tools/lib/h5trav.c | 36 | ||||
-rw-r--r-- | tools/misc/h5debug.c | 5 |
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); |