diff options
author | Staale Smedseng <staale.smedseng@sun.com> | 2009-08-28 17:51:31 +0200 |
---|---|---|
committer | Staale Smedseng <staale.smedseng@sun.com> | 2009-08-28 17:51:31 +0200 |
commit | 1ba25ae47caace207cda0be2b7994a1a845e6cce (patch) | |
tree | 4278d9f3353d5c86ca327f6ac2680c001e809843 /client | |
parent | 5edd807a7ab72fc16472293fc94a7eb8e762e2b7 (diff) | |
download | mariadb-git-1ba25ae47caace207cda0be2b7994a1a845e6cce.tar.gz |
Bug #43414 Parenthesis (and other) warnings compiling MySQL
with gcc 4.3.2
This patch fixes a number of GCC warnings about variables used
before initialized. A new macro UNINIT_VAR() is introduced for
use in the variable declaration, and LINT_INIT() usage will be
gradually deprecated. (A workaround is used for g++, pending a
patch for a g++ bug.)
GCC warnings for unused results (attribute warn_unused_result)
for a number of system calls (present at least in later
Ubuntus, where the usual void cast trick doesn't work) are
also fixed.
client/mysqlmanager-pwgen.c:
A fix for warn_unused_result, adding fallback to use of
srand()/rand() if /dev/random cannot be used. Also actually
adds calls to rand() in the second branch so that it actually
creates a random password.
Diffstat (limited to 'client')
-rw-r--r-- | client/mysql.cc | 3 | ||||
-rw-r--r-- | client/mysql_upgrade.c | 3 | ||||
-rw-r--r-- | client/mysqladmin.cc | 6 | ||||
-rw-r--r-- | client/mysqlmanager-pwgen.c | 19 | ||||
-rw-r--r-- | client/mysqltest.c | 15 |
5 files changed, 27 insertions, 19 deletions
diff --git a/client/mysql.cc b/client/mysql.cc index 0d61ed4ec88..d103a3eec17 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -3728,7 +3728,8 @@ com_edit(String *buffer,char *line __attribute__((unused))) !(editor = (char *)getenv("VISUAL"))) editor = "vi"; strxmov(buff,editor," ",filename,NullS); - (void) system(buff); + if(system(buff) == -1) + goto err; MY_STAT stat_arg; if (!my_stat(filename,&stat_arg,MYF(MY_WME))) diff --git a/client/mysql_upgrade.c b/client/mysql_upgrade.c index ff414fff592..efa23610574 100644 --- a/client/mysql_upgrade.c +++ b/client/mysql_upgrade.c @@ -526,6 +526,7 @@ static int upgrade_already_done(void) FILE *in; char upgrade_info_file[FN_REFLEN]= {0}; char buf[sizeof(MYSQL_SERVER_VERSION)+1]; + char *res; if (get_upgrade_info_file_name(upgrade_info_file)) return 0; /* Could not get filename => not sure */ @@ -538,7 +539,7 @@ static int upgrade_already_done(void) will be detected by the strncmp */ bzero(buf, sizeof(buf)); - fgets(buf, sizeof(buf), in); + res= fgets(buf, sizeof(buf), in); my_fclose(in, MYF(0)); diff --git a/client/mysqladmin.cc b/client/mysqladmin.cc index 24b95be8626..699c2081b86 100644 --- a/client/mysqladmin.cc +++ b/client/mysqladmin.cc @@ -1050,14 +1050,16 @@ static void usage(void) static int drop_db(MYSQL *mysql, const char *db) { char name_buff[FN_REFLEN+20], buf[10]; + char *input; + if (!option_force) { puts("Dropping the database is potentially a very bad thing to do."); puts("Any data stored in the database will be destroyed.\n"); printf("Do you really want to drop the '%s' database [y/N] ",db); fflush(stdout); - VOID(fgets(buf,sizeof(buf)-1,stdin)); - if ((*buf != 'y') && (*buf != 'Y')) + input= fgets(buf, sizeof(buf)-1, stdin); + if (!input || ((*input != 'y') && (*input != 'Y'))) { puts("\nOK, aborting database drop!"); return -1; diff --git a/client/mysqlmanager-pwgen.c b/client/mysqlmanager-pwgen.c index 568358b1cda..1be4d8b6970 100644 --- a/client/mysqlmanager-pwgen.c +++ b/client/mysqlmanager-pwgen.c @@ -104,29 +104,34 @@ void get_pass(char* pw, int len) { FILE* fp; char* pw_end=pw+len; + size_t elements_read= 0; /* /dev/random is more secure than rand() because the seed is easy to predict, so we resort to rand() only if /dev/random is not available */ if ((fp=fopen("/dev/random","r"))) { - fread(pw,len,1,fp); - fclose(fp); - while (pw<pw_end) + if ((elements_read= fread(pw,len,1,fp))) { - char tmp= 'a'+((uint)*pw % 26); - *pw++= tmp; + while (pw<pw_end) + { + char tmp= 'a'+((uint)*pw % 26); + *pw++= tmp; + } } + fclose(fp); } - else + + if (elements_read != 1) { srand(time(NULL)); while (pw<pw_end) { - char tmp= 'a'+((uint)*pw % 26); + char tmp= 'a'+((uint)rand() % 26); *pw++= tmp; } } + *pw_end=0; } diff --git a/client/mysqltest.c b/client/mysqltest.c index 24d021b7239..79df511641d 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -426,10 +426,12 @@ DYNAMIC_STRING ds_res, ds_progress, ds_warning_messages; char builtin_echo[FN_REFLEN]; +static void cleanup_and_exit(int exit_code) __attribute__((noreturn)); + void die(const char *fmt, ...) - ATTRIBUTE_FORMAT(printf, 1, 2); + ATTRIBUTE_FORMAT(printf, 1, 2) __attribute__((noreturn)); void abort_not_supported_test(const char *fmt, ...) - ATTRIBUTE_FORMAT(printf, 1, 2); + ATTRIBUTE_FORMAT(printf, 1, 2) __attribute__((noreturn)); void verbose_msg(const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 1, 2); void warning_msg(const char *fmt, ...) @@ -3385,10 +3387,9 @@ void do_wait_for_slave_to_stop(struct st_command *c __attribute__((unused))) MYSQL* mysql = &cur_con->mysql; for (;;) { - MYSQL_RES *res; + MYSQL_RES *UNINIT_VAR(res); MYSQL_ROW row; int done; - LINT_INIT(res); if (mysql_query(mysql,"show status like 'Slave_running'") || !(res=mysql_store_result(mysql))) @@ -4710,13 +4711,12 @@ my_bool end_of_query(int c) int read_line(char *buf, int size) { - char c, last_quote; + char c, UNINIT_VAR(last_quote); char *p= buf, *buf_end= buf + size - 1; int skip_char= 0; enum {R_NORMAL, R_Q, R_SLASH_IN_Q, R_COMMENT, R_LINE_START} state= R_LINE_START; DBUG_ENTER("read_line"); - LINT_INIT(last_quote); start_lineno= cur_file->lineno; DBUG_PRINT("info", ("Starting to read at lineno: %d", start_lineno)); @@ -5978,8 +5978,7 @@ void run_query_normal(struct st_connection *cn, struct st_command *command, if (!disable_result_log) { - ulonglong affected_rows; /* Ok to be undef if 'disable_info' is set */ - LINT_INIT(affected_rows); + ulonglong UNINIT_VAR(affected_rows); /* Ok to be undef if 'disable_info' is set */ if (res) { |