From 3ae6df9c49e6e2aabf60d3d3914a2fa58e1f5655 Mon Sep 17 00:00:00 2001
From: David Gow <davidgow@google.com>
Date: Tue, 26 Apr 2016 13:50:39 -0700
Subject: [PATCH] Fix issues caught by Clang's -Wpointer-bool-conversion
 warning

Fix instances where a pointer is always converted to a true value. Since
this value is known beforehand, it can be safely removed. These include
checking the address of an array, taking the address of a local variable, or
taking the address of a member variable. In most cases, the pointer is removed
from the conditional. In a few instances, the address-of operator is removed,
or the check is performed on the first element of the array. In a couple
of cases, attribute(nonnull) is changed in function declarations.

This only applies to the core client/server (and InnoDB), other plugins or storage
engines may still have issues.
---
 libmysql/libmysql.c                  | 2 +-
 sql/log.cc                           | 2 +-
 sql/log_event_old.cc                 | 4 ++--
 sql/sql_acl.cc                       | 2 +-
 sql/sql_audit.cc                     | 2 +-
 storage/innobase/include/dict0dict.h | 4 ++--
 6 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c
index 446f1da..ab7d1fe 100644
--- a/libmysql/libmysql.c
+++ b/libmysql/libmysql.c
@@ -1404,7 +1404,7 @@ void set_stmt_errmsg(MYSQL_STMT *stmt, NET *net)
   DBUG_ASSERT(stmt != 0);
 
   stmt->last_errno= net->last_errno;
-  if (net->last_error && net->last_error[0])
+  if (net->last_error[0])
     strmov(stmt->last_error, net->last_error);
   strmov(stmt->sqlstate, net->sqlstate);
 
diff --git a/sql/log.cc b/sql/log.cc
index efc3b12..99b6122 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -1291,7 +1291,7 @@ bool LOGGER::slow_log_print(THD *thd, const char *query, uint query_length,
 
     /* fill in user_host value: the format is "%s[%s] @ %s [%s]" */
     user_host_len= (strxnmov(user_host_buff, MAX_USER_HOST_SIZE,
-                             sctx->priv_user ? sctx->priv_user : "", "[",
+                             sctx->priv_user, "[",
                              sctx->user ? sctx->user : (thd->slave_thread ? "SQL_SLAVE" : ""), "] @ ",
                              sctx->host ? sctx->host : "", " [",
                              sctx->ip ? sctx->ip : "", "]", NullS) -
diff --git a/sql/log_event_old.cc b/sql/log_event_old.cc
index ad68275..f586565 100644
--- a/sql/log_event_old.cc
+++ b/sql/log_event_old.cc
@@ -1656,7 +1656,7 @@ int Old_rows_log_event::do_apply_event(rpl_group_info *rgi)
 	rli->report(ERROR_LEVEL, thd->net.last_errno, NULL,
                     "Error in %s event: row application failed. %s",
                     get_type_str(),
-                    thd->net.last_error ? thd->net.last_error : "");
+                    thd->net.last_error);
        thd->is_slave_error= 1;
 	break;
       }
@@ -1696,7 +1696,7 @@ int Old_rows_log_event::do_apply_event(rpl_group_info *rgi)
                 "on table %s.%s. %s",
                 get_type_str(), table->s->db.str,
                 table->s->table_name.str,
-                thd->net.last_error ? thd->net.last_error : "");
+                thd->net.last_error);
 
     /*
       If one day we honour --skip-slave-errors in row-based replication, and
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index 502e9ff..37514c8 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -10636,7 +10636,7 @@ void fill_effective_table_privileges(THD *thd, GRANT_INFO *grant,
   /* global privileges */
   grant->privilege= sctx->master_access;
 
-  if (!sctx->priv_user)
+  if (!sctx->priv_user[0])
   {
     DBUG_PRINT("info", ("privilege 0x%lx", grant->privilege));
     DBUG_VOID_RETURN;                         // it is slave
diff --git a/sql/sql_audit.cc b/sql/sql_audit.cc
index b659054..8ea2646 100644
--- a/sql/sql_audit.cc
+++ b/sql/sql_audit.cc
@@ -369,7 +369,7 @@ int initialize_audit_plugin(st_plugin_int *plugin)
 {
   st_mysql_audit *data= (st_mysql_audit*) plugin->plugin->info;
   
-  if (!data->class_mask || !data->event_notify ||
+  if (!data->event_notify ||
       !data->class_mask[0])
   {
     sql_print_error("Plugin '%s' has invalid data.",
diff --git a/storage/innobase/include/dict0dict.h b/storage/innobase/include/dict0dict.h
index 4332867..5ebec42 100644
--- a/storage/innobase/include/dict0dict.h
+++ b/storage/innobase/include/dict0dict.h
@@ -1530,7 +1530,7 @@ dict_table_get_index_on_name(
 /*=========================*/
 	dict_table_t*	table,	/*!< in: table */
 	const char*	name)	/*!< in: name of the index to find */
-	__attribute__((nonnull, warn_unused_result));
+	__attribute__((nonnull(1), warn_unused_result));
 /**********************************************************************//**
 In case there is more than one index with the same name return the index
 with the min(id).
@@ -1770,7 +1770,7 @@ dict_set_corrupted_index_cache_only(
 /*================================*/
 	dict_index_t*	index,		/*!< in/out: index */
 	dict_table_t*	table)		/*!< in/out: table */
-	__attribute__((nonnull));
+	__attribute__((nonnull(1)));
 
 /**********************************************************************//**
 Flags a table with specified space_id corrupted in the table dictionary
-- 
2.8.0.rc3.226.g39d4020

