From 78826aa070ff0b65703dfcd8e106bdeec5c6a5d5 Mon Sep 17 00:00:00 2001 From: wangbin579 Date: Mon, 20 Aug 2018 18:15:16 +0800 Subject: [PATCH] Optimize more code hinted by coverity scan --- plugins/admin/admin-commands.c | 6 +++--- src/chassis-log.c | 2 +- src/chassis-sql-log.c | 2 +- src/chassis-sql-log.h | 3 ++- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/admin/admin-commands.c b/plugins/admin/admin-commands.c index 72b9954..5e8ca19 100644 --- a/plugins/admin/admin-commands.c +++ b/plugins/admin/admin-commands.c @@ -2057,7 +2057,7 @@ void admin_select_single_table(network_mysqld_con* con) } void admin_sql_log_start(network_mysqld_con* con) { - if (!con || !con->srv || !con->srv->sql_mgr) { + if (!con->srv->sql_mgr) { network_mysqld_con_send_error(con->client, C("Unexpected error")); return; } @@ -2079,7 +2079,7 @@ void admin_sql_log_start(network_mysqld_con* con) { } void admin_sql_log_stop(network_mysqld_con* con) { - if (!con || !con->srv || !con->srv->sql_mgr) { + if (!con->srv->sql_mgr) { network_mysqld_con_send_error(con->client, C("Unexpected error")); return; } @@ -2097,7 +2097,7 @@ void admin_sql_log_stop(network_mysqld_con* con) { } void admin_sql_log_status(network_mysqld_con* con) { - if (!con || !con->srv || !con->srv->sql_mgr) { + if (!con->srv->sql_mgr) { network_mysqld_con_send_error(con->client, C("Unexpected error")); return; } diff --git a/src/chassis-log.c b/src/chassis-log.c index 7eb001f..1d0eb38 100644 --- a/src/chassis-log.c +++ b/src/chassis-log.c @@ -207,7 +207,7 @@ chassis_log_write(chassis_log *log, int log_level, GString *str) int log_fd = log->log_file_fd; if (log_fd == -1) { - return; + return -1; } p = buffer; diff --git a/src/chassis-sql-log.c b/src/chassis-sql-log.c index ce3f636..3335d1f 100644 --- a/src/chassis-sql-log.c +++ b/src/chassis-sql-log.c @@ -432,7 +432,7 @@ log_sql_backend(network_mysqld_con *con, injection *inj) inj->id, inj->bytes, inj->rows, latency_ms, inj->qstat.query_status == MYSQLD_PACKET_OK ? "OK" : "ERR", GET_COM_NAME(con->parse.command),//type - con->parse.command == 23 ? "" : (inj->query != NULL ? GET_COM_STRING(inj->query) : ""));//sql + con->parse.command == COM_STMT_EXECUTE ? "" : (inj->query != NULL ? GET_COM_STRING(inj->query) : ""));//sql rfifo_write(mgr->fifo, message->str, message->len); g_string_free(message, TRUE); diff --git a/src/chassis-sql-log.h b/src/chassis-sql-log.h index dfb9da8..0b2a8d1 100644 --- a/src/chassis-sql-log.h +++ b/src/chassis-sql-log.h @@ -18,7 +18,8 @@ #define GET_COM_NAME(com_type) \ ((((gushort)com_type) <= 31) ? com_command_name[((gushort)com_type)].com_str : "UNKNOWN TYPE") -#define GET_COM_STRING(query) GET_COM_NAME((query)->str[0]), ((query)->len > 1 ? ((query)->str + 1) : "") + +#define GET_COM_STRING(query) ((query)->len > 1 ? ((query)->str + 1) : "") typedef struct com_string { char *com_str;