]> xenbits.xensource.com Git - libvirt.git/commitdiff
let gcc's -Wformat do its job; avoid "make syntax-check" failure
authorJim Meyering <meyering@redhat.com>
Wed, 17 Dec 2008 17:22:43 +0000 (17:22 +0000)
committerJim Meyering <meyering@redhat.com>
Wed, 17 Dec 2008 17:22:43 +0000 (17:22 +0000)
* src/util.c (virAsprintf): Remove trailing space.
* src/util.h (virAsprintf): Use ATTRIBUTE_FORMAT.
* HACKING (Printf-style functions): New section.

ChangeLog
HACKING
src/util.c
src/util.h

index 5ca5dec74b1c445b94bf411e1721f7e63d180826..323120d911911c6abefeb62f27c8c778e6f8590c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Wed Dec 17 18:10:51 +0100 2008 Jim Meyering <meyering@redhat.com>
+
+       let gcc's -Wformat do its job; avoid "make syntax-check" failure
+       * src/util.c (virAsprintf): Remove trailing space.
+       * src/util.h (virAsprintf): Use ATTRIBUTE_FORMAT.
+       * HACKING (Printf-style functions): New section.
+
 Wed Dec 17 16:43:39 GMT 2008 Daniel P. Berrange <berrange@redhat.com>
 
        * src/libvirt.c: Add missing checks for read-only connection
diff --git a/HACKING b/HACKING
index 3945833f29a141191d7cfc7511ae2ed73c59020a..e088da8628a80f0d77ca6a87b52f8fa8fbe9dda4 100644 (file)
--- a/HACKING
+++ b/HACKING
@@ -247,6 +247,22 @@ are some special reasons why you cannot include these files
 explicitly.
 
 
+Printf-style functions
+======================
+
+Whenever you add a new printf-style function, i.e., one with a format
+string argument and following "..." in its prototype, be sure to use
+gcc's printf attribute directive in the prototype.  For example, here's
+the one for virAsprintf, in util.h:
+
+    int virAsprintf(char **strp, const char *fmt, ...)
+       ATTRIBUTE_FORMAT(printf, 2, 3);
+
+This makes it so gcc's -Wformat and -Wformat-security options can do
+their jobs and cross-check format strings with the number and types
+of arguments.
+
+
 
                 Libvirt commiters guidelines
                 ============================
index 12097d41aa8b7ad135ca3dd53f5fc00c4061ac08..9eda378509d16029528dd1ad38e65de52ad29034 100644 (file)
@@ -1158,7 +1158,7 @@ virParseNumber(const char **str)
  *
  * like asprintf but makes sure *strp == NULL on failure
  */
-int 
+int
 virAsprintf(char **strp, const char *fmt, ...)
 {
     va_list ap;
index 3d603dc5312fe053f5c13145322f42ff1a4beb95..0475bd3569d66d75ea50fde6467f00604084e6b5 100644 (file)
@@ -112,7 +112,8 @@ int virMacAddrCompare (const char *mac1, const char *mac2);
 
 void virSkipSpaces(const char **str);
 int virParseNumber(const char **str);
-int virAsprintf(char **strp, const char *fmt, ...);
+int virAsprintf(char **strp, const char *fmt, ...)
+    ATTRIBUTE_FORMAT(printf, 2, 3);
 
 #define VIR_MAC_BUFLEN 6
 #define VIR_MAC_PREFIX_BUFLEN 3