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

[Libvir] [PATCH] Check calls to printf-like functions (and some fixes) (second version)




--
Emerging Technologies, Red Hat  http://et.redhat.com/~rjones/
64 Baker Street, London, W1U 7DF     Mobile: +44 7866 314 421
 "[Negative numbers] darken the very whole doctrines of the equations
 and make dark of the things which are in their nature excessively
 obvious and simple" (Francis Maseres FRS, mathematician, 1759)
diff -urN --exclude=CVS --exclude=.git --exclude='*.pem' --exclude=demoCA --exclude=.gitignore --exclude='*.orig' --exclude='*.bak' libvirt-cvs/qemud/conf.c libvirt-printf/qemud/conf.c
--- libvirt-cvs/qemud/conf.c	2007-03-16 11:04:46.000000000 +0000
+++ libvirt-printf/qemud/conf.c	2007-03-16 13:59:43.000000000 +0000
@@ -1622,14 +1622,14 @@
     towrite = strlen(xml);
     if (write(fd, xml, towrite) != towrite) {
         qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
-                         "cannot write config file %s",
+                         "cannot write config file %s: %s",
                          network->configFile, strerror(errno));
         goto cleanup;
     }
 
     if (close(fd) < 0) {
         qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
-                         "cannot save config file %s",
+                         "cannot save config file %s: %s",
                          network->configFile, strerror(errno));
         goto cleanup;
     }
diff -urN --exclude=CVS --exclude=.git --exclude='*.pem' --exclude=demoCA --exclude=.gitignore --exclude='*.orig' --exclude='*.bak' libvirt-cvs/qemud/driver.h libvirt-printf/qemud/driver.h
--- libvirt-cvs/qemud/driver.h	2007-02-23 09:03:25.000000000 +0000
+++ libvirt-printf/qemud/driver.h	2007-03-16 13:54:20.000000000 +0000
@@ -28,7 +28,8 @@
 #include "internal.h"
 
 void qemudReportError(struct qemud_server *server,
-                      int code, const char *fmt, ...);
+                      int code, const char *fmt, ...)
+    ATTRIBUTE_FORMAT(printf,3,4);
 
 int qemudGetCPUInfo(unsigned int *cpus, unsigned int *mhz,
                     unsigned int *nodes, unsigned int *sockets,
diff -urN --exclude=CVS --exclude=.git --exclude='*.pem' --exclude=demoCA --exclude=.gitignore --exclude='*.orig' --exclude='*.bak' libvirt-cvs/qemud/internal.h libvirt-printf/qemud/internal.h
--- libvirt-cvs/qemud/internal.h	2007-03-16 11:04:46.000000000 +0000
+++ libvirt-printf/qemud/internal.h	2007-03-16 14:13:26.000000000 +0000
@@ -37,7 +37,7 @@
 #include <ansidecl.h>
 #endif
 #ifndef ATTRIBUTE_UNUSED
-#define ATTRIBUTE_UNUSED __attribute__((unused))
+#define ATTRIBUTE_UNUSED __attribute__((__unused__))
 #endif
 #ifndef ATTRIBUTE_FORMAT
 #define ATTRIBUTE_FORMAT(args...) __attribute__((__format__ (args)))
@@ -332,12 +332,13 @@
 int qemudShutdownNetworkDaemon(struct qemud_server *server,
                                struct qemud_network *network);
 
-void qemudLog(int priority, const char *fmt, ...);
+void qemudLog(int priority, const char *fmt, ...)
+    ATTRIBUTE_FORMAT(printf,2,3);
 
 #ifdef ENABLE_DEBUG
 #define qemudDebug(...) qemudLog(QEMUD_DEBUG, __VA_ARGS__)
 #else
-#define qemudDebug(fmt, ...) do { } while(0);
+#define qemudDebug(fmt, ...) do {} while(0)
 #endif
 
 static inline int
diff -urN --exclude=CVS --exclude=.git --exclude='*.pem' --exclude=demoCA --exclude=.gitignore --exclude='*.orig' --exclude='*.bak' libvirt-cvs/src/internal.h libvirt-printf/src/internal.h
--- libvirt-cvs/src/internal.h	2007-03-16 11:04:46.000000000 +0000
+++ libvirt-printf/src/internal.h	2007-03-16 13:59:43.000000000 +0000
@@ -26,33 +26,33 @@
 #define _N(str) dgettext(GETTEXT_PACKAGE, (str))
 #define gettext_noop(str) (str)
 
+#ifdef __GNUC__
+#ifdef HAVE_ANSIDECL_H
+#include <ansidecl.h>
+#endif
+
 /**
  * ATTRIBUTE_UNUSED:
  *
  * Macro to flag conciously unused parameters to functions
  */
-#ifdef __GNUC__
-#ifdef HAVE_ANSIDECL_H
-#include <ansidecl.h>
-#endif
 #ifndef ATTRIBUTE_UNUSED
-#define ATTRIBUTE_UNUSED __attribute__((unused))
+#define ATTRIBUTE_UNUSED __attribute__((__unused__))
 #endif
-#else
-#define ATTRIBUTE_UNUSED
+
+/**
+ * ATTRIBUTE_FORMAT
+ *
+ * Macro used to check printf/scanf-like functions, if compiling
+ * with gcc.
+ */
+#ifndef ATTRIBUTE_FORMAT
+#define ATTRIBUTE_FORMAT(args...) __attribute__((__format__ (args)))
 #endif
 
-#ifndef __attribute__
-/* This feature is available in gcc versions 2.5 and later.  */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
-#  define __attribute__(Spec) /* empty */
-# endif
-/* The __-protected variants of `format' and `printf' attributes
-   are accepted by gcc versions 2.6.4 (effectively 2.7) and later.  */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
-#  define __format__ format
-#  define __printf__ printf
-# endif
+#else
+#define ATTRIBUTE_UNUSED
+#define ATTRIBUTE_FORMAT(...)
 #endif
 
 /**
@@ -211,7 +211,8 @@
 		     const char *str1,
 		     const char *str2,
 		     const char *str3,
-		     int int1, int int2, const char *msg, ...);
+		     int int1, int int2, const char *msg, ...)
+  ATTRIBUTE_FORMAT(printf, 12, 13);
 const char *__virErrorMsg(virErrorNumber error, const char *info);
 
 /************************************************************************
diff -urN --exclude=CVS --exclude=.git --exclude='*.pem' --exclude=demoCA --exclude=.gitignore --exclude='*.orig' --exclude='*.bak' libvirt-cvs/src/sexpr.h libvirt-printf/src/sexpr.h
--- libvirt-cvs/src/sexpr.h	2006-08-26 16:30:44.000000000 +0100
+++ libvirt-printf/src/sexpr.h	2007-03-16 13:54:18.000000000 +0000
@@ -13,6 +13,8 @@
 #ifndef _LIBVIR_SEXPR_H_
 #define _LIBVIR_SEXPR_H_
 
+#include "internal.h"
+
 #include <sys/types.h>
 
 enum sexpr_type {
@@ -45,6 +47,7 @@
 
 /* lookup in S-Expressions */
 const char *sexpr_node(struct sexpr *sexpr, const char *node);
-const char *sexpr_fmt_node(struct sexpr *sexpr, const char *fmt, ...);
+const char *sexpr_fmt_node(struct sexpr *sexpr, const char *fmt, ...)
+  ATTRIBUTE_FORMAT(printf,2,3);
 struct sexpr *sexpr_lookup(struct sexpr *sexpr, const char *node);
 #endif
diff -urN --exclude=CVS --exclude=.git --exclude='*.pem' --exclude=demoCA --exclude=.gitignore --exclude='*.orig' --exclude='*.bak' libvirt-cvs/src/test.c libvirt-printf/src/test.c
--- libvirt-cvs/src/test.c	2007-03-16 11:04:46.000000000 +0000
+++ libvirt-printf/src/test.c	2007-03-16 13:59:44.000000000 +0000
@@ -1306,7 +1306,7 @@
                       uuid[8], uuid[9], uuid[10], uuid[11],
                       uuid[12], uuid[13], uuid[14], uuid[15]);
 
-    virBufferVSprintf(buf, "  <memory>%d</memory>\n", con->domains[domidx].info.maxMem);
+    virBufferVSprintf(buf, "  <memory>%lu</memory>\n", con->domains[domidx].info.maxMem);
     virBufferVSprintf(buf, "  <vcpu>%d</vcpu>\n", con->domains[domidx].info.nrVirtCpu);
     virBufferVSprintf(buf, "  <on_reboot>%s</on_reboot>\n", testRestartFlagToString(con->domains[domidx].onReboot));
     virBufferVSprintf(buf, "  <on_poweroff>%s</on_poweroff>\n", testRestartFlagToString(con->domains[domidx].onPoweroff));
diff -urN --exclude=CVS --exclude=.git --exclude='*.pem' --exclude=demoCA --exclude=.gitignore --exclude='*.orig' --exclude='*.bak' libvirt-cvs/src/xm_internal.c libvirt-printf/src/xm_internal.c
--- libvirt-cvs/src/xm_internal.c	2007-03-16 11:04:46.000000000 +0000
+++ libvirt-printf/src/xm_internal.c	2007-03-16 13:59:44.000000000 +0000
@@ -952,7 +952,7 @@
 
     if (vnc) {
         virBufferVSprintf(buf,
-                          "    <graphics type='vnc' port='%d'",
+                          "    <graphics type='vnc' port='%ld'",
                           (vncunused ? -1 : 5900+vncdisplay));
         if (vnclisten) {
             virBufferVSprintf(buf, " listen='%s'", vnclisten);
diff -urN --exclude=CVS --exclude=.git --exclude='*.pem' --exclude=demoCA --exclude=.gitignore --exclude='*.orig' --exclude='*.bak' libvirt-cvs/src/xml.c libvirt-printf/src/xml.c
--- libvirt-cvs/src/xml.c	2007-03-15 12:54:37.000000000 +0000
+++ libvirt-printf/src/xml.c	2007-03-16 13:59:44.000000000 +0000
@@ -254,7 +254,7 @@
                     if (port == -1)
                         virBufferAdd(buf, "(vncunused 1)", 13);
                     else if (port >= 5900)
-                        virBufferVSprintf(buf, "(vncdisplay %d)", port - 5900);
+                        virBufferVSprintf(buf, "(vncdisplay %ld)", port - 5900);
                     xmlFree(vncport);
                 }
                 if (vnclisten != NULL) {
@@ -318,7 +318,7 @@
                 if (port == -1)
                     virBufferAdd(buf, "(vncunused 1)", 13);
                 else if (port >= 5900)
-                    virBufferVSprintf(buf, "(vncdisplay %d)", port - 5900);
+                    virBufferVSprintf(buf, "(vncdisplay %ld)", port - 5900);
                 xmlFree(vncport);
             }
             if (vnclisten != NULL) {
@@ -418,11 +418,11 @@
 
     if (boot_dev) {
         if (xmlStrEqual(boot_dev, BAD_CAST "fd")) {
-            virBufferVSprintf(buf, "(boot a)", (const char *) boot_dev);
+            virBufferVSprintf(buf, "(boot a)" /*, (const char *) boot_dev*/);
         } else if (xmlStrEqual(boot_dev, BAD_CAST "cdrom")) {
-            virBufferVSprintf(buf, "(boot d)", (const char *) boot_dev);
+            virBufferVSprintf(buf, "(boot d)" /*, (const char *) boot_dev*/);
         } else if (xmlStrEqual(boot_dev, BAD_CAST "hd")) {
-            virBufferVSprintf(buf, "(boot c)", (const char *) boot_dev);
+            virBufferVSprintf(buf, "(boot c)" /*, (const char *) boot_dev*/);
         } else {
             /* Any other type of boot dev is unsupported right now */
             virXMLError(conn, VIR_ERR_XML_ERROR, NULL, 0);
diff -urN --exclude=CVS --exclude=.git --exclude='*.pem' --exclude=demoCA --exclude=.gitignore --exclude='*.orig' --exclude='*.bak' libvirt-cvs/src/xml.h libvirt-printf/src/xml.h
--- libvirt-cvs/src/xml.h	2007-03-16 11:04:46.000000000 +0000
+++ libvirt-printf/src/xml.h	2007-03-16 13:59:44.000000000 +0000
@@ -6,6 +6,7 @@
 #define __VIR_XML_H__
 
 #include "libvirt/libvirt.h"
+#include "internal.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -27,7 +28,8 @@
 virBufferPtr virBufferNew(unsigned int size);
 void virBufferFree(virBufferPtr buf);
 int virBufferAdd(virBufferPtr buf, const char *str, int len);
-int virBufferVSprintf(virBufferPtr buf, const char *format, ...);
+int virBufferVSprintf(virBufferPtr buf, const char *format, ...)
+  ATTRIBUTE_FORMAT(printf, 2, 3);
 int virBufferStrcat(virBufferPtr buf, ...);
 
 char *virDomainParseXMLDesc(virConnectPtr conn, const char *xmldesc, char **name, int xendConfigVersion);

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


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