[libxslt] Fix libxslt format warnings



commit 866fc3b67e8a0595a0c4950a22ee71fa43228de6
Author: David Kilzer <ddkilzer webkit org>
Date:   Mon Mar 28 15:23:09 2016 +0200

    Fix libxslt format warnings
    
    * config.h.in: Let autoconf have its way with the file.
    * configure.in: Replace "-Wformat" with
    "-Wformat=2 -Wmissing-format-attribute".  Add
    "-Wformat=2 -Wmissing-format-attribute" to default CFLAGS.
    * libxslt/transform.c:
    (xsltDocumentElem): Fix missing placeholder in format string.
    Make "unsupported method" format strings more consistent by
    putting method name in parenthesis.
    (xsltApplyStylesheetInternal): Ditto.
    * libxslt/xsltconfig.h.in:
    (LIBXSLT_ATTR_FORMAT): Add macro to decorate functions that
    have format string arguments.
    * libxslt/xsltutils.c:
    (xsltGenericErrorDefaultFunc): Add macro to decorate functions
    that have format string arguments.
    (xsltGenericDebugDefaultFunc): Ditto.
    * libxslt/xsltutils.h:
    (xsltTransformError): Add LIBXSLT_ATTR_FORMAT macro.
    * xsltproc/xsltproc.c:
    (endTimer): Add predeclaration with LIBXSLT_ATTR_FORMAT macro.
    
    Fixes bug #762006.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=762006

 configure.in            |    4 ++--
 libxslt/transform.c     |    8 ++++----
 libxslt/xsltconfig.h.in |   11 +++++++++++
 libxslt/xsltutils.c     |    4 ++--
 libxslt/xsltutils.h     |    2 +-
 xsltproc/xsltproc.c     |    3 +++
 6 files changed, 23 insertions(+), 9 deletions(-)
---
diff --git a/configure.in b/configure.in
index b49c1c8..fee676f 100644
--- a/configure.in
+++ b/configure.in
@@ -431,7 +431,7 @@ if [[ "${LOGNAME}" = "veillard" -a "`pwd`" = "/u/veillard/XSLT" ]] || \
     then
        with_mem_debug="yes"
     fi
-    CFLAGS="-Wall -g -O -ansi -pedantic -W -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs 
-Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align 
-Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline "
+    CFLAGS="-Wall -g -O -ansi -pedantic -W -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs 
-Wformat=2 -Wmissing-format-attribute -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow 
-Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes 
-Wnested-externs -Winline "
 fi
 
 AC_ARG_WITH(debug, [  --with-debug            Add the debugging code (on)])
@@ -525,7 +525,7 @@ if test "${GCC}" != "yes" ; then
                ;;
     esac
 else
-    CFLAGS="${CFLAGS} -Wall"
+    CFLAGS="${CFLAGS} -Wall -Wformat=2 -Wmissing-format-attribute"
     case "${host}" in
           alpha*-*-linux* )
               CFLAGS="${CFLAGS} -mieee"
diff --git a/libxslt/transform.c b/libxslt/transform.c
index 86b0a82..8a6d727 100644
--- a/libxslt/transform.c
+++ b/libxslt/transform.c
@@ -3714,7 +3714,7 @@ xsltDocumentElem(xsltTransformContextPtr ctxt, xmlNodePtr node,
            xmlDictReference(res->dict);
        } else if (xmlStrEqual(method, (const xmlChar *) "xhtml")) {
            xsltTransformError(ctxt, NULL, inst,
-            "xsltDocumentElem: unsupported method xhtml\n",
+            "xsltDocumentElem: unsupported method xhtml (%s)\n",
                             style->method);
            ctxt->type = XSLT_OUTPUT_HTML;
            res = htmlNewDocNoDtD(doctypeSystem, doctypePublic);
@@ -3735,7 +3735,7 @@ xsltDocumentElem(xsltTransformContextPtr ctxt, xmlNodePtr node,
 #endif
        } else {
            xsltTransformError(ctxt, NULL, inst,
-                            "xsltDocumentElem: unsupported method %s\n",
+                            "xsltDocumentElem: unsupported method (%s)\n",
                             style->method);
            goto error;
        }
@@ -5973,7 +5973,7 @@ xsltApplyStylesheetInternal(xsltStylesheetPtr style, xmlDocPtr doc,
 #endif
         } else if (xmlStrEqual(method, (const xmlChar *) "xhtml")) {
            xsltTransformError(ctxt, NULL, (xmlNodePtr) doc,
-               "xsltApplyStylesheetInternal: unsupported method xhtml, using html\n",
+               "xsltApplyStylesheetInternal: unsupported method xhtml (%s), using html\n",
                style->method);
             ctxt->type = XSLT_OUTPUT_HTML;
             res = htmlNewDoc(doctypeSystem, doctypePublic);
@@ -6000,7 +6000,7 @@ xsltApplyStylesheetInternal(xsltStylesheetPtr style, xmlDocPtr doc,
 #endif
         } else {
            xsltTransformError(ctxt, NULL, (xmlNodePtr) doc,
-               "xsltApplyStylesheetInternal: unsupported method %s\n",
+               "xsltApplyStylesheetInternal: unsupported method (%s)\n",
                style->method);
             goto error;
         }
diff --git a/libxslt/xsltconfig.h.in b/libxslt/xsltconfig.h.in
index b4cac6d..6e4e328 100644
--- a/libxslt/xsltconfig.h.in
+++ b/libxslt/xsltconfig.h.in
@@ -153,6 +153,17 @@ extern "C" {
 #endif
 
 /**
+ * LIBXSLT_ATTR_FORMAT:
+ *
+ * This macro is used to indicate to GCC the parameters are printf-like
+ */
+#ifdef __GNUC__
+#define LIBXSLT_ATTR_FORMAT(fmt,args) __attribute__((__format__(__printf__,fmt,args)))
+#else
+#define LIBXSLT_ATTR_FORMAT(fmt,args)
+#endif
+
+/**
  * LIBXSLT_PUBLIC:
  *
  * This macro is used to declare PUBLIC variables for Cygwin and for MSC on Windows
diff --git a/libxslt/xsltutils.c b/libxslt/xsltutils.c
index c7d9f1e..1646c44 100644
--- a/libxslt/xsltutils.c
+++ b/libxslt/xsltutils.c
@@ -519,7 +519,7 @@ xsltMessage(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst) {
  *
  * Default handler for out of context error messages.
  */
-static void
+static void LIBXSLT_ATTR_FORMAT(2,3)
 xsltGenericErrorDefaultFunc(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) {
     va_list args;
 
@@ -565,7 +565,7 @@ xsltSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler) {
  *
  * Default handler for out of context error messages.
  */
-static void
+static void LIBXSLT_ATTR_FORMAT(2,3)
 xsltGenericDebugDefaultFunc(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) {
     va_list args;
 
diff --git a/libxslt/xsltutils.h b/libxslt/xsltutils.h
index a86f844..789865a 100644
--- a/libxslt/xsltutils.h
+++ b/libxslt/xsltutils.h
@@ -165,7 +165,7 @@ XSLTPUBFUN void XSLTCALL
                                                 xsltStylesheetPtr style,
                                                 xmlNodePtr node,
                                                 const char *msg,
-                                                ...);
+                                                ...) LIBXSLT_ATTR_FORMAT(4,5);
 
 XSLTPUBFUN int XSLTCALL
                xsltSetCtxtParseOptions         (xsltTransformContextPtr ctxt,
diff --git a/xsltproc/xsltproc.c b/xsltproc/xsltproc.c
index e39552a..3f49cec 100644
--- a/xsltproc/xsltproc.c
+++ b/xsltproc/xsltproc.c
@@ -7,6 +7,7 @@
  */
 
 #include "libxslt/libxslt.h"
+#include "libxslt/xsltconfig.h"
 #include "libexslt/exslt.h"
 #include <stdio.h>
 #ifdef HAVE_STRING_H
@@ -236,6 +237,8 @@ my_gettimeofday(struct timeval *tvp, void *tzp)
 #endif /* HAVE_SYS_TIMEB_H */
 #endif /* !HAVE_GETTIMEOFDAY */
 
+static void endTimer(const char *format, ...) LIBXSLT_ATTR_FORMAT(1,2);
+
 #if defined(HAVE_GETTIMEOFDAY)
 static struct timeval begin, endtime;
 /*


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]