summaryrefslogtreecommitdiffstats
path: root/tools/h5dump/h5dump_xml.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/h5dump/h5dump_xml.c')
-rw-r--r--tools/h5dump/h5dump_xml.c110
1 files changed, 55 insertions, 55 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';