[Spice-devel] [PATCH spice 03/12] Fix multiple printf format problems

Daniel P. Berrange berrange at redhat.com
Mon Apr 2 04:23:38 PDT 2012


From: "Daniel P. Berrange" <berrange at redhat.com>

All printf var-args style methods should be annotation with
their format. All format strings must be const strings.

* client/application.cpp, client/cmd_line_parser.cpp,
  client/hot_keys.cpp: Avoid non-const format
* client/client_net_socket.cpp: Fix broken format specifier
* client/red_peer.cpp: Fix missing format specifier
* client/platform.h: Add SPICE_GNUC_PRINTF annotation to term_printf
* client/utils.h: Add SPICE_GNUC_PRINTF annotation to string_printf
* server/glz_encoder_config.h, server/red_worker.c: Add
  SPICE_GNUC_PRINTF annotation to warning callbacks

Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
---
 client/application.cpp       |    2 +-
 client/client_net_socket.cpp |    2 +-
 client/cmd_line_parser.cpp   |    2 +-
 client/hot_keys.cpp          |    2 +-
 client/platform.h            |    2 +-
 client/red_peer.cpp          |    2 +-
 client/utils.h               |    2 +-
 server/glz_encoder_config.h  |    6 +++---
 server/red_worker.c          |   12 ++++++------
 9 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/client/application.cpp b/client/application.cpp
index 43fe7fa..d9da67f 100644
--- a/client/application.cpp
+++ b/client/application.cpp
@@ -2359,7 +2359,7 @@ bool Application::process_cmd_line(int argc, char** argv, bool &full_screen)
         case SPICE_OPT_VERSION: {
             std::ostringstream os;
             os << argv[0] << " "<< PACKAGE_VERSION << std::endl;
-            Platform::term_printf(os.str().c_str());
+            Platform::term_printf("%s", os.str().c_str());
             return false;
         }
         case SPICE_OPT_HOST:
diff --git a/client/client_net_socket.cpp b/client/client_net_socket.cpp
index e9f1e77..9df6801 100644
--- a/client/client_net_socket.cpp
+++ b/client/client_net_socket.cpp
@@ -147,7 +147,7 @@ void ClientNetSocket::push_send(SendBuffer& buf)
     }
 
     if (_fin_pending || _close_pending) {
-        THROW("%s: unexpected send attempt for connection_id=% - shutdown send pending",
+        THROW("%s: unexpected send attempt for connection_id=%d - shutdown send pending",
               __FUNCTION__, _id);
     }
 
diff --git a/client/cmd_line_parser.cpp b/client/cmd_line_parser.cpp
index b937fb0..12d5945 100644
--- a/client/cmd_line_parser.cpp
+++ b/client/cmd_line_parser.cpp
@@ -514,5 +514,5 @@ void CmdLineParser::show_help()
     }
 
     os << "\n";
-    Platform::term_printf(os.str().c_str());
+    Platform::term_printf("%s", os.str().c_str());
 }
diff --git a/client/hot_keys.cpp b/client/hot_keys.cpp
index f98a4bb..3ac3532 100644
--- a/client/hot_keys.cpp
+++ b/client/hot_keys.cpp
@@ -141,7 +141,7 @@ void HotKeysParser::add_hotkey(const std::string& hotkey, const CommandsMap& com
     if (commands_map.find(command_name) == commands_map.end()) {
         char buf[1000];
         sprintf(buf, "invalid action bname %s", command_name.c_str());
-        THROW(buf);
+        THROW("%s", buf);
     }
     int command_id = commands_map.find(command_name)->second;
     std::string keys = hotkey.substr(key_start + 1);
diff --git a/client/platform.h b/client/platform.h
index 2025ad9..913bcde 100644
--- a/client/platform.h
+++ b/client/platform.h
@@ -42,7 +42,7 @@ public:
     static void path_append(std::string& path, const std::string& partial_path);
     static uint64_t get_process_id();
     static uint64_t get_thread_id();
-    static void term_printf(const char* format, ...);
+    static SPICE_GNUC_PRINTF(1, 2) void term_printf(const char* format, ...);
     static void error_beep();
 
     static const MonitorsList& init_monitors();
diff --git a/client/red_peer.cpp b/client/red_peer.cpp
index 64e43d5..10640c8 100644
--- a/client/red_peer.cpp
+++ b/client/red_peer.cpp
@@ -38,7 +38,7 @@ static void ssl_error()
     unsigned long last_error = ERR_peek_last_error();
 
     ERR_print_errors_fp(stderr);
-    THROW_ERR(SPICEC_ERROR_CODE_SSL_ERROR, "SSL Error:", ERR_error_string(last_error, NULL));
+    THROW_ERR(SPICEC_ERROR_CODE_SSL_ERROR, "SSL Error: %s", ERR_error_string(last_error, NULL));
 }
 
 RedPeer::RedPeer()
diff --git a/client/utils.h b/client/utils.h
index 8f32008..c23e04f 100644
--- a/client/utils.h
+++ b/client/utils.h
@@ -98,7 +98,7 @@ static inline void set_bit_be(const void* addr, int bit)
 int str_to_port(const char *str);
 
 void string_vprintf(std::string& str, const char* format, va_list ap);
-void string_printf(std::string& str, const char *format, ...);
+SPICE_GNUC_PRINTF(2, 3) void string_printf(std::string& str, const char *format, ...);
 
 template<class T>
 class FreeObject {
diff --git a/server/glz_encoder_config.h b/server/glz_encoder_config.h
index 157e3a2..886c68b 100644
--- a/server/glz_encoder_config.h
+++ b/server/glz_encoder_config.h
@@ -25,9 +25,9 @@ typedef void GlzUsrImageContext;
 typedef struct GlzEncoderUsrContext GlzEncoderUsrContext;
 
 struct GlzEncoderUsrContext {
-    void (*error)(GlzEncoderUsrContext *usr, const char *fmt, ...);
-    void (*warn)(GlzEncoderUsrContext *usr, const char *fmt, ...);
-    void (*info)(GlzEncoderUsrContext *usr, const char *fmt, ...);
+    SPICE_GNUC_PRINTF(2, 3) void (*error)(GlzEncoderUsrContext *usr, const char *fmt, ...);
+    SPICE_GNUC_PRINTF(2, 3) void (*warn)(GlzEncoderUsrContext *usr, const char *fmt, ...);
+    SPICE_GNUC_PRINTF(2, 3) void (*info)(GlzEncoderUsrContext *usr, const char *fmt, ...);
     void    *(*malloc)(GlzEncoderUsrContext *usr, int size);
     void (*free)(GlzEncoderUsrContext *usr, void *ptr);
 
diff --git a/server/red_worker.c b/server/red_worker.c
index 30be5bb..bd58f96 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -5265,7 +5265,7 @@ static int red_display_free_some_independent_glz_drawables(DisplayChannelClient
 /******************************************************
  *              Encoders callbacks
 *******************************************************/
-static void quic_usr_error(QuicUsrContext *usr, const char *fmt, ...)
+static SPICE_GNUC_PRINTF(2, 3) void quic_usr_error(QuicUsrContext *usr, const char *fmt, ...)
 {
     EncoderData *usr_data = &(((QuicData *)usr)->data);
     va_list ap;
@@ -5278,7 +5278,7 @@ static void quic_usr_error(QuicUsrContext *usr, const char *fmt, ...)
     longjmp(usr_data->jmp_env, 1);
 }
 
-static void lz_usr_error(LzUsrContext *usr, const char *fmt, ...)
+static SPICE_GNUC_PRINTF(2, 3) void lz_usr_error(LzUsrContext *usr, const char *fmt, ...)
 {
     EncoderData *usr_data = &(((LzData *)usr)->data);
     va_list ap;
@@ -5291,7 +5291,7 @@ static void lz_usr_error(LzUsrContext *usr, const char *fmt, ...)
     longjmp(usr_data->jmp_env, 1);
 }
 
-static void glz_usr_error(GlzEncoderUsrContext *usr, const char *fmt, ...)
+static SPICE_GNUC_PRINTF(2, 3) void glz_usr_error(GlzEncoderUsrContext *usr, const char *fmt, ...)
 {
     EncoderData *usr_data = &(((GlzData *)usr)->data);
     va_list ap;
@@ -5306,7 +5306,7 @@ static void glz_usr_error(GlzEncoderUsrContext *usr, const char *fmt, ...)
                                         // and the client
 }
 
-static void quic_usr_warn(QuicUsrContext *usr, const char *fmt, ...)
+static SPICE_GNUC_PRINTF(2, 3) void quic_usr_warn(QuicUsrContext *usr, const char *fmt, ...)
 {
     EncoderData *usr_data = &(((QuicData *)usr)->data);
     va_list ap;
@@ -5317,7 +5317,7 @@ static void quic_usr_warn(QuicUsrContext *usr, const char *fmt, ...)
     spice_printerr("%s", usr_data->message_buf);
 }
 
-static void lz_usr_warn(LzUsrContext *usr, const char *fmt, ...)
+static SPICE_GNUC_PRINTF(2, 3) void lz_usr_warn(LzUsrContext *usr, const char *fmt, ...)
 {
     EncoderData *usr_data = &(((LzData *)usr)->data);
     va_list ap;
@@ -5328,7 +5328,7 @@ static void lz_usr_warn(LzUsrContext *usr, const char *fmt, ...)
     spice_printerr("%s", usr_data->message_buf);
 }
 
-static void glz_usr_warn(GlzEncoderUsrContext *usr, const char *fmt, ...)
+static SPICE_GNUC_PRINTF(2, 3) void glz_usr_warn(GlzEncoderUsrContext *usr, const char *fmt, ...)
 {
     EncoderData *usr_data = &(((GlzData *)usr)->data);
     va_list ap;
-- 
1.7.7.6



More information about the Spice-devel mailing list