[libxslt] Rework xsltNumberFormat to fix warning
- From: Nick Wellnhofer <nwellnhof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxslt] Rework xsltNumberFormat to fix warning
- Date: Sun, 13 Dec 2015 19:34:38 +0000 (UTC)
commit 22c698987e462731c3ac81968660376077610ec4
Author: Nick Wellnhofer <wellnhofer aevum de>
Date: Sun Dec 13 19:59:37 2015 +0100
Rework xsltNumberFormat to fix warning
Commit 15f148e 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.
libxslt/numbers.c | 35 +++++++++++++++++------------------
1 files changed, 17 insertions(+), 18 deletions(-)
---
diff --git a/libxslt/numbers.c b/libxslt/numbers.c
index 0884e4c..e3209e0 100644
--- a/libxslt/numbers.c
+++ b/libxslt/numbers.c
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]