Commit 22c69898 authored by Nick Wellnhofer's avatar Nick Wellnhofer

Rework xsltNumberFormat to fix warning

Commit 15f148ee introduced a warning because a const pointer was passed
to xmlFree. Rework xsltNumberFormat to tokenize numbers before
allocating the output buffer and use a local xmlChar* if the format
must be evaluated dynamically.
parent 07c31851
......@@ -713,24 +713,29 @@ xsltNumberFormat(xsltTransformContextPtr ctxt,
int amount, i;
double number;
xsltFormat tokens;
int tempformat = 0;
if ((data->format == NULL) && (data->has_format != 0)) {
data->format = xsltEvalAttrValueTemplate(ctxt, data->node,
if (data->format != NULL) {
xsltNumberFormatTokenize(data->format, &tokens);
}
else {
xmlChar *format;
/* The format needs to be recomputed each time */
if (data->has_format == 0)
return;
format = xsltEvalAttrValueTemplate(ctxt, data->node,
(const xmlChar *) "format",
XSLT_NAMESPACE);
tempformat = 1;
}
if (data->format == NULL) {
return;
if (format == NULL)
return;
xsltNumberFormatTokenize(format, &tokens);
xmlFree(format);
}
output = xmlBufferCreate();
if (output == NULL)
goto XSLT_NUMBER_FORMAT_END;
xsltNumberFormatTokenize(data->format, &tokens);
/*
* Evaluate the XPath expression to find the value(s)
*/
......@@ -797,6 +802,9 @@ xsltNumberFormat(xsltTransformContextPtr ctxt,
/* Insert number as text node */
xsltCopyTextString(ctxt, ctxt->insert, xmlBufferContent(output), 0);
xmlBufferFree(output);
XSLT_NUMBER_FORMAT_END:
if (tokens.start != NULL)
xmlFree(tokens.start);
if (tokens.end != NULL)
......@@ -805,15 +813,6 @@ xsltNumberFormat(xsltTransformContextPtr ctxt,
if (tokens.tokens[i].separator != NULL)
xmlFree(tokens.tokens[i].separator);
}
XSLT_NUMBER_FORMAT_END:
if (tempformat == 1) {
/* The format need to be recomputed each time */
xmlFree(data->format);
data->format = NULL;
}
if (output != NULL)
xmlBufferFree(output);
}
static int
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment