Last-Update: 2019-02-05
Forwarded: no
Author: Dmitry Smirnov <onlyjob@member.fsf.org>
Description: Use correct format specifier for size_t

%zu instead of %lu, otherwise on 32 bit:
~~~~
 library/ssh/SSHCommon.cpp:171:15: error: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'ssize_t' {aka 'int'} [-Werror=format=]
     logDebug2("SSH bufferSize: %lu\n", bufferSize);
               ^~~~~~~~~~~~~~~~~~~~~~~  ~~~~~~~~~~
 library/ssh/SSHCommon.cpp:172:15: error: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'std::size_t' {aka 'unsigned int'} [-Werror=format=]
     logDebug2("SSH connectTimeout: %lu\n", connectTimeout);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~  ~~~~~~~~~~~~~~
 library/ssh/SSHCommon.cpp:173:15: error: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'std::size_t' {aka 'unsigned int'} [-Werror=format=]
     logDebug2("SSH readWriteTimeout: %lu\n", readWriteTimeout);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ~~~~~~~~~~~~~~~~
 library/ssh/SSHCommon.cpp:174:15: error: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'std::size_t' {aka 'unsigned int'} [-Werror=format=]
     logDebug2("SSH commandTimeout: %lu\n", commandTimeout);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~  ~~~~~~~~~~~~~~
 library/ssh/SSHCommon.cpp:175:15: error: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'std::size_t' {aka 'unsigned int'} [-Werror=format=]
     logDebug2("SSH commandRetryCount: %lu\n", commandRetryCount);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ~~~~~~~~~~~~~~~~~
 library/ssh/SSHCommon.cpp:183:15: error: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'std::size_t' {aka 'unsigned int'} [-Werror=format=]
     logDebug2("SSH remote ssh port: %lu\n", remoteSSHport);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~  ~~~~~~~~~~~~~

 library/ssh/SSHSession.cpp:150:16: error: format '%lu' expects argument of type 'long unsigned int', but argument 5 has type 'std::size_t' {aka 'unsigned int'} [-Werror=format=]
       logError("Unable to connect: %s:%lu\nError was: %s\n", config.remoteSSHhost.c_str(), config.remoteSSHport,
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                ~~~~~~~~~~~~~~~~~~~~
 library/ssh/SSHSession.cpp: In member function 'std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> ssh::SSHSession::execCmd(std::__cxx11::string, std::size_t)':
 library/ssh/SSHSession.cpp:363:15: error: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'std::size_t' {aka 'unsigned int'} [-Werror=format=]
     logDebug3("Bytes read: %lu\n", bytesRead);
               ^~~~~~~~~~~~~~~~~~~  ~~~~~~~~~
 library/ssh/SSHSession.cpp: In member function 'std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> ssh::SSHSession::execCmdSudo(std::__cxx11::string, std::__cxx11::string, std::__cxx11::string, std::size_t)':
 library/ssh/SSHSession.cpp:482:15: error: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'std::size_t' {aka 'unsigned int'} [-Werror=format=]
     logDebug3("Bytes read: %lu\n", bytesRead);
               ^~~~~~~~~~~~~~~~~~~  ~~~~~~~~~

 backend/wbprivate/sqlide/wb_sql_editor_form.cpp:1880:17: error: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'unsigned int' [-Werror=format=]
       logDebug3("Executing statement range: %lu, %lu...\n", statement_range.first, statement_range.second);
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ~~~~~~~~~~~~~~~~~~~~~
~~~~

--- a/library/ssh/SSHCommon.cpp
+++ b/library/ssh/SSHCommon.cpp
@@ -167,21 +167,21 @@
   }
 
   void SSHConnectionConfig::dumpConfig() const {
     logDebug2("SSH Connection config info:\n");
-    logDebug2("SSH bufferSize: %lu\n", bufferSize);
-    logDebug2("SSH connectTimeout: %lu\n", connectTimeout);
-    logDebug2("SSH readWriteTimeout: %lu\n", readWriteTimeout);
-    logDebug2("SSH commandTimeout: %lu\n", commandTimeout);
-    logDebug2("SSH commandRetryCount: %lu\n", commandRetryCount);
+    logDebug2("SSH bufferSize: %zu\n", bufferSize);
+    logDebug2("SSH connectTimeout: %zu\n", connectTimeout);
+    logDebug2("SSH readWriteTimeout: %zu\n", readWriteTimeout);
+    logDebug2("SSH commandTimeout: %zu\n", commandTimeout);
+    logDebug2("SSH commandRetryCount: %zu\n", commandRetryCount);
     logDebug2("SSH optionsDir: %s\n", optionsDir.c_str());
     logDebug2("SSH known hosts file: %s\n", knownHostsFile.c_str());
     logDebug2("SSH local host: %s\n", localhost.c_str());
     logDebug2("SSH local port: %d\n", localport);
     logDebug2("SSH remote host: %s\n", remotehost.c_str());
     logDebug2("SSH remote port: %d\n", remoteport);
     logDebug2("SSH remote ssh host: %s\n", remoteSSHhost.c_str());
-    logDebug2("SSH remote ssh port: %lu\n", remoteSSHport);
+    logDebug2("SSH remote ssh port: %zu\n", remoteSSHport);
     logDebug2("SSH strict host key check: %s\n", strictHostKeyCheck ? "yes" : "no");
   }
 
   bool operator==(const SSHConnectionConfig &tun1, const SSHConnectionConfig &tun2) {
--- a/library/ssh/SSHSession.cpp
+++ b/library/ssh/SSHSession.cpp
@@ -146,9 +146,9 @@
 
     try {
       _session->connect();
     } catch (ssh::SshException &exc) {
-      logError("Unable to connect: %s:%lu\nError was: %s\n", config.remoteSSHhost.c_str(), config.remoteSSHport,
+      logError("Unable to connect: %s:%zu\nError was: %s\n", config.remoteSSHhost.c_str(), config.remoteSSHport,
                exc.getError().c_str());
       return std::make_tuple(SSHReturnType::CONNECTION_FAILURE, exc.getError());
     }
 
@@ -359,9 +359,9 @@
         throw SSHTunnelException("Too much data to read, limit is: " + std::to_string(logSize) + ". You can change the limit in the Workbench Preferences.");
       }
     } while (true);
 
-    logDebug3("Bytes read: %lu\n", bytesRead);
+    logDebug3("Bytes read: %zu\n", bytesRead);
     return std::make_tuple(so.str(), retError, channel->getExitStatus());
   }
 
   /**
@@ -478,9 +478,9 @@
         throw SSHTunnelException("Too much data to read, limit is: " + std::to_string(logSize) + ". You can change the limit in the Workbench Preferences.");
       }
     } while (true);
 
-    logDebug3("Bytes read: %lu\n", bytesRead);
+    logDebug3("Bytes read: %zu\n", bytesRead);
     return std::make_tuple(so.str(), retError, channel->getExitStatus());
   }
 
   void SSHSession::reconnect() {
--- a/backend/wbprivate/sqlide/wb_sql_editor_form.cpp
+++ b/backend/wbprivate/sqlide/wb_sql_editor_form.cpp
@@ -2015,9 +2015,9 @@
     ssize_t total_result_count = (editor != nullptr) ? editor->resultset_count() : 0; // Consider pinned result sets.
 
     bool results_left = false;
     for (auto &statement_range : statement_ranges) {
-      logDebug3("Executing statement range: %lu, %lu...\n", statement_range.first, statement_range.second);
+      logDebug3("Executing statement range: %zu, %zu...\n", statement_range.first, statement_range.second);
 
       statement = sql->substr(statement_range.first, statement_range.second);
       std::list<std::string> sub_statements;
       sql_facade->splitSqlScript(statement, sub_statements);
