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 +- 7 files changed, 7 insertions(+), 9 deletions(-) (limited to 'client') 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 { -- cgit