X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_xml.c;h=d6963c8bdfbb51eb8dd11551a90780c098ffe12e;hb=e5649c2775438bbb04baf9a8bd53fa70363c4235;hp=4b4a8f6db2b49a5f2e17bd11d43cc564929e1a71;hpb=786d89d4e5c6bb25c3dd07ec3bb375c5964f2af2;p=palacios-OLD.git diff --git a/palacios/src/palacios/vmm_xml.c b/palacios/src/palacios/vmm_xml.c index 4b4a8f6..d6963c8 100644 --- a/palacios/src/palacios/vmm_xml.c +++ b/palacios/src/palacios/vmm_xml.c @@ -62,7 +62,7 @@ struct v3_xml_root { // additional data for the root tag static char * empty_attrib_list[] = { NULL }; // empty, null terminated array of strings -static void * tmp_realloc(void * old_ptr, uint_t old_size, uint_t new_size) { +static void * tmp_realloc(void * old_ptr, size_t old_size, size_t new_size) { void * new_buf = V3_Malloc(new_size); if (new_buf == NULL) { @@ -1103,7 +1103,10 @@ static char *ampencode(const char *s, size_t len, char **dst, size_t *dlen, const char * e; for (e = s + len; s != e; s++) { - while (*dlen + 10 > *max) *dst = tmp_realloc(*dst, *max, *max += V3_XML_BUFSIZE); + while (*dlen + 10 > *max) { + *dst = tmp_realloc(*dst, *max, *max + V3_XML_BUFSIZE); + *max += V3_XML_BUFSIZE; + } switch (*s) { case '\0': return *dst; @@ -1134,14 +1137,21 @@ static char *toxml_r(struct v3_xml * xml, char **s, size_t *len, size_t *max, // parent character content up to this tag *s = ampencode(txt + start, xml->off - start, s, len, max, 0); - while (*len + strlen(xml->name) + 4 > *max) // reallocate s - *s = tmp_realloc(*s, *max, *max += V3_XML_BUFSIZE); + while (*len + strlen(xml->name) + 4 > *max) { + // reallocate s + *s = tmp_realloc(*s, *max, *max + V3_XML_BUFSIZE); + *max += V3_XML_BUFSIZE; + } + *len += sprintf(*s + *len, "<%s", xml->name); // open tag for (i = 0; xml->attr[i]; i += 2) { // tag attributes if (v3_xml_attr(xml, xml->attr[i]) != xml->attr[i + 1]) continue; - while (*len + strlen(xml->attr[i]) + 7 > *max) // reallocate s - *s = tmp_realloc(*s, *max, *max += V3_XML_BUFSIZE); + while (*len + strlen(xml->attr[i]) + 7 > *max) { + // reallocate s + *s = tmp_realloc(*s, *max, *max + V3_XML_BUFSIZE); + *max += V3_XML_BUFSIZE; + } *len += sprintf(*s + *len, " %s=\"", xml->attr[i]); ampencode(xml->attr[i + 1], -1, s, len, max, 1); @@ -1152,8 +1162,11 @@ static char *toxml_r(struct v3_xml * xml, char **s, size_t *len, size_t *max, for (j = 1; attr[i] && attr[i][j]; j += 3) { // default attributes if (! attr[i][j + 1] || v3_xml_attr(xml, attr[i][j]) != attr[i][j + 1]) continue; // skip duplicates and non-values - while (*len + strlen(attr[i][j]) + 7 > *max) // reallocate s - *s = tmp_realloc(*s, *max, *max += V3_XML_BUFSIZE); + while (*len + strlen(attr[i][j]) + 7 > *max) { + // reallocate s + *s = tmp_realloc(*s, *max, *max + V3_XML_BUFSIZE); + *max += V3_XML_BUFSIZE; + } *len += sprintf(*s + *len, " %s=\"", attr[i][j]); ampencode(attr[i][j + 1], -1, s, len, max, 1); @@ -1164,8 +1177,11 @@ static char *toxml_r(struct v3_xml * xml, char **s, size_t *len, size_t *max, *s = (xml->child) ? toxml_r(xml->child, s, len, max, 0, attr) //child : ampencode(xml->txt, -1, s, len, max, 0); //data - while (*len + strlen(xml->name) + 4 > *max) // reallocate s - *s = tmp_realloc(*s, *max, *max += V3_XML_BUFSIZE); + while (*len + strlen(xml->name) + 4 > *max) { + // reallocate s + *s = tmp_realloc(*s, *max, *max + V3_XML_BUFSIZE); + *max += V3_XML_BUFSIZE; + } *len += sprintf(*s + *len, "", xml->name); // close tag