From 6a8b7585e2051baa911b665ed713835bc65515d6 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Tue, 13 Mar 2012 15:28:26 +0000 Subject: Fix multiple printf format problems 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 --- client/application.cpp | 2 +- client/client_net_socket.cpp | 2 +- client/cmd_line_parser.cpp | 2 +- client/hot_keys.cpp | 4 +--- 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(+), 18 deletions(-) diff --git a/client/application.cpp b/client/application.cpp index 43fe7fa7..d9da67f5 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 e9f1e770..9df68014 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 b937fb0f..12d5945b 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 2d0b9db4..763ba2ca 100644 --- a/client/hot_keys.cpp +++ b/client/hot_keys.cpp @@ -139,9 +139,7 @@ void HotKeysParser::add_hotkey(const std::string& hotkey, const CommandsMap& com std::string command_name = hotkey.substr(0, key_start); if (commands_map.find(command_name) == commands_map.end()) { - char buf[1000]; - snprintf(buf, sizeof(buf), "invalid action bname %s", command_name.c_str()); - THROW(buf); + THROW("invalid action bname %s", command_name.c_str()); } 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 2025ad9d..913bcde4 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 64e43d5b..10640c8d 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 8f320085..c23e04fe 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 FreeObject { diff --git a/server/glz_encoder_config.h b/server/glz_encoder_config.h index 157e3a21..886c68ba 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 3bb7d3ef..1a0438ea 100644 --- a/server/red_worker.c +++ b/server/red_worker.c @@ -5274,7 +5274,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; @@ -5287,7 +5287,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; @@ -5300,7 +5300,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; @@ -5315,7 +5315,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; @@ -5326,7 +5326,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; @@ -5337,7 +5337,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; -- cgit