Add printf attribute to all variadic functions

The test methods that take printf style input now have the printf
attribute. This enables format checks making oversights less likely.

Also fixed any existing errors in the code. Only the one in
test_binlog_fnc.cpp would've had an actual effect.
This commit is contained in:
Markus Mäkelä 2018-06-21 15:33:22 +03:00
parent a59c0c61ce
commit 9737962add
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
9 changed files with 20 additions and 14 deletions

View File

@ -64,7 +64,7 @@ int main(int argc, char *argv[])
"yum install -y MariaDB-gssapi-server MariaDB-gssapi-client krb5-server krb5-workstation pam_krb5", true);
Test->maxscales->ssh_node_f(0, true, (char *)
"yum install -y MariaDB-gssapi-server MariaDB-gssapi-client krb5-server krb5-workstation pam_krb5", true);
"yum install -y MariaDB-gssapi-server MariaDB-gssapi-client krb5-server krb5-workstation pam_krb5");
Test->tprintf("Configuring Kerberos server\n");
Test->maxscales->ssh_node(0, (char *)

View File

@ -26,6 +26,8 @@
#include <string>
#include <vector>
#include <maxbase/ccdefs.hh>
typedef std::vector<std::string> Row;
typedef std::vector<Row> Result;
@ -119,7 +121,7 @@ static MYSQL* open_conn_no_db(int port, std::string ip, std::string user, std::s
* @param ... Parameters for @c format
* @return 0 in case of success
*/
int execute_query(MYSQL* conn, const char* format, ...);
int execute_query(MYSQL* conn, const char* format, ...) mxb_attribute((format(printf, 2, 3)));
/**
* @brief execute_query_from_file Read a line from a file, trim leading and trailing whitespace and execute it.

View File

@ -1231,7 +1231,7 @@ int Mariadb_nodes::disable_ssl()
local_result += connect();
sprintf(str, "DROP USER %s; grant all privileges on *.* to '%s'@'%%' identified by '%s';", user_name,
user_name, password);
local_result += execute_query(nodes[0], (char *) "");
local_result += execute_query(nodes[0], "%s", "");
close_connections();
for (int i = 0; i < N; i++)
@ -1363,7 +1363,7 @@ void Mariadb_nodes::disable_server_setting(int node, const char* setting)
void Mariadb_nodes::add_server_setting(int node, const char* setting)
{
ssh_node_f(node, true, "sudo sed -i '$a [server]' /etc/my.cnf.d/server*.cnf", setting);
ssh_node_f(node, true, "sudo sed -i '$a [server]' /etc/my.cnf.d/server*.cnf");
ssh_node_f(node, true, "sudo sed -i '$a %s' /etc/my.cnf.d/server*.cnf", setting);
}

View File

@ -23,7 +23,7 @@ void client_thr(TestConnections* test, int id)
test->try_query(conn, "INSERT INTO test.t1 (a) VALUES (%d)", id);
int last_id = mysql_insert_id(conn);
test->try_query(conn, "UPDATE test.t1 SET a = -1 WHERE id = %d", last_id);
test->try_query(conn, "COMMIT", id);
test->try_query(conn, "COMMIT");
test->try_query(conn, "DELETE FROM test.t1 WHERE id = %d", last_id);
sleep(1);
}

View File

@ -22,7 +22,7 @@ void change_master(TestConnections& test, int slave, int master, const char* nam
"SET GLOBAL gtid_slave_pos='0-1-0';"
"CHANGE MASTER %s TO master_host='%s', master_port=3306, master_user='%s', master_password='%s', master_use_gtid=slave_pos;"
"START ALL SLAVES",
source.c_str(), test.repl->IP[master], test.repl->user_name, test.repl->password, source.c_str());
source.c_str(), test.repl->IP[master], test.repl->user_name, test.repl->password);
}
void check_status(TestConnections& test, const StringSet& expected_master, const StringSet& expected_slave)

View File

@ -48,7 +48,7 @@ void tune_rowcount(TestConnections& test)
filename.c_str());
auto end = Clock::now();
dur = duration_cast<milliseconds>(end - start);
test.try_query(test.maxscales->conn_rwsplit[0], "TRUNCATE TABLE test.t1", filename.c_str());
test.try_query(test.maxscales->conn_rwsplit[0], "TRUNCATE TABLE test.t1");
remove(filename.c_str());

View File

@ -7,6 +7,8 @@
#include <set>
#include <string>
#include <maxbase/ccdefs.hh>
typedef std::set<std::string> StringSet;
@ -112,7 +114,7 @@ public:
* @param pointer to variable to store process exit code
* @return output of the command
*/
char *ssh_node_output_f(int node, bool sudo, int * exit_code, const char* format, ...);
char *ssh_node_output_f(int node, bool sudo, int* exit_code, const char* format, ...) mxb_attribute((format(printf, 5, 6)));
char *ssh_node_output(int node, const char *ssh, bool sudo, int *exit_code);
/**
@ -123,7 +125,7 @@ public:
* @return exit code of the coomand
*/
int ssh_node(int node, const char *ssh, bool sudo);
int ssh_node_f(int node, bool sudo, const char* format, ...);
int ssh_node_f(int node, bool sudo, const char* format, ...) mxb_attribute((format(printf, 4, 5)));
/**
* @brief Copy a local file to the Node i machine

View File

@ -26,7 +26,7 @@ int check_sha1(TestConnections* Test)
Test->set_timeout(50);
Test->tprintf("ls before FLUSH LOGS");
Test->tprintf("Maxscale");
Test->maxscales->ssh_node_f(0, true, "ls -la %s/mar-bin.0000*", Test->maxscales->maxscale_binlog_dir);
Test->maxscales->ssh_node_f(0, true, "ls -la %s/mar-bin.0000*", Test->maxscales->maxscale_binlog_dir[0]);
Test->tprintf("Master");
Test->set_timeout(50);
Test->maxscales->ssh_node(0, "ls -la /var/lib/mysql/mar-bin.0000*", false);
@ -40,7 +40,7 @@ int check_sha1(TestConnections* Test)
Test->tprintf("ls after first FLUSH LOGS");
Test->tprintf("Maxscale");
Test->set_timeout(50);
Test->maxscales->ssh_node_f(0, true, "ls -la %s/mar-bin.0000*", Test->maxscales->maxscale_binlog_dir);
Test->maxscales->ssh_node_f(0, true, "ls -la %s/mar-bin.0000*", Test->maxscales->maxscale_binlog_dir[0]);
Test->tprintf("Master");
Test->set_timeout(50);
@ -57,7 +57,7 @@ int check_sha1(TestConnections* Test)
Test->tprintf("ls before FLUSH LOGS");
Test->tprintf("Maxscale");
Test->maxscales->ssh_node_f(0, true, "ls -la %s/mar-bin.0000*", Test->maxscales->maxscale_binlog_dir);
Test->maxscales->ssh_node_f(0, true, "ls -la %s/mar-bin.0000*", Test->maxscales->maxscale_binlog_dir[0]);
Test->tprintf("Master");
Test->set_timeout(50);
@ -69,7 +69,7 @@ int check_sha1(TestConnections* Test)
Test->tprintf("FILE: 000000%d", i);
Test->set_timeout(50);
s_maxscale = Test->maxscales->ssh_node_output_f(0, true, &exit_code, "sha1sum %s/mar-bin.00000%d",
Test->maxscales->maxscale_binlog_dir, i);
Test->maxscales->maxscale_binlog_dir[0], i);
if (s_maxscale != NULL)
{
x = strchr(s_maxscale, ' ');

View File

@ -12,6 +12,8 @@
#include <vector>
#include <thread>
#include <maxbase/ccdefs.hh>
typedef std::set<std::string> StringSet;
/**
@ -456,7 +458,7 @@ public:
* @param sql SQL string
* @return 0 if ok
*/
int try_query(MYSQL *conn, const char *sql, ...);
int try_query(MYSQL *conn, const char *sql, ...) mxb_attribute((format(printf, 3, 4)));
/**
* @brief try_query_all Executes SQL query on all MaxScale connections