From 80246ac8b8d0d2db08feae2a643a3dc89f9022d6 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Wed, 10 Nov 2010 19:14:47 -0200 Subject: [PATCH 1/4] Bug#58057: 5.1 libmysql/libmysql.c unused variable/compile failure Bug#57995: Compiler flag change build error on OSX 10.4: my_getncpus.c Bug#57996: Compiler flag change build error on OSX 10.5 : bind.c Bug#57994: Compiler flag change build error : my_redel.c Bug#57993: Compiler flag change build error on FreeBsd 7.0 : regexec.c Bug#57992: Compiler flag change build error on FreeBsd : mf_keycache.c Bug#57997: Compiler flag change build error on OSX 10.6: debug_sync.cc Fix assorted compiler generated warnings. --- cmd-line-utils/readline/bind.c | 2 +- include/m_string.h | 4 +++- include/my_compiler.h | 5 +++++ libmysql/libmysql.c | 4 ++-- mysys/mf_keycache.c | 10 +++++----- mysys/my_getncpus.c | 3 ++- regex/regexec.c | 5 +++-- sql/debug_sync.cc | 2 +- sql/handler.cc | 2 +- sql/slave.cc | 2 +- sql/sql_partition.cc | 4 ++-- storage/myisam/ft_nlq_search.c | 2 +- storage/myisam/mi_create.c | 4 +--- storage/myisammrg/myrg_open.c | 2 +- tests/mysql_client_test.c | 6 +++--- 15 files changed, 32 insertions(+), 25 deletions(-) diff --git a/cmd-line-utils/readline/bind.c b/cmd-line-utils/readline/bind.c index c669322f436..0ea8b1ca126 100644 --- a/cmd-line-utils/readline/bind.c +++ b/cmd-line-utils/readline/bind.c @@ -855,7 +855,7 @@ _rl_read_init_file (filename, include_level) { register int i; char *buffer, *openname, *line, *end; - size_t file_size; + size_t file_size = 0; current_readline_init_file = filename; current_readline_init_include_level = include_level; diff --git a/include/m_string.h b/include/m_string.h index 3e5cd063b7b..933da84c336 100644 --- a/include/m_string.h +++ b/include/m_string.h @@ -73,7 +73,9 @@ extern "C" { extern void *(*my_str_malloc)(size_t); extern void (*my_str_free)(void *); -#if defined(HAVE_STPCPY) +#if MY_GNUC_PREREQ(3, 4) +#define strmov(dest, src) __builtin_stpcpy(dest, src) +#elif defined(HAVE_STPCPY) #define strmov(A,B) stpcpy((A),(B)) #ifndef stpcpy extern char *stpcpy(char *, const char *); /* For AIX with gcc 2.95.3 */ diff --git a/include/my_compiler.h b/include/my_compiler.h index c7d334999d0..5f898621159 100644 --- a/include/my_compiler.h +++ b/include/my_compiler.h @@ -76,6 +76,11 @@ /** Generic (compiler-independent) features. */ + +#ifndef MY_GNUC_PREREQ +# define MY_GNUC_PREREQ(maj, min) (0) +#endif + #ifndef MY_ALIGNOF # ifdef __cplusplus template struct my_alignof_helper { char m1; type m2; }; diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 8c612b6894e..deb7cd10d2a 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -131,8 +131,8 @@ int STDCALL mysql_server_init(int argc __attribute__((unused)), mysql_port = MYSQL_PORT; #ifndef MSDOS { - struct servent *serv_ptr; - char *env; + char *env; + struct servent *serv_ptr __attribute__((unused)); /* if builder specifically requested a default port, use that diff --git a/mysys/mf_keycache.c b/mysys/mf_keycache.c index 8042dc2828b..b7faf7c1b95 100644 --- a/mysys/mf_keycache.c +++ b/mysys/mf_keycache.c @@ -3917,11 +3917,11 @@ restart: if (!(block->status & (BLOCK_IN_EVICTION | BLOCK_IN_SWITCH | BLOCK_REASSIGNED))) { - struct st_hash_link *next_hash_link; - my_off_t next_diskpos; - File next_file; - uint next_status; - uint hash_requests; + struct st_hash_link *UNINIT_VAR(next_hash_link); + my_off_t UNINIT_VAR(next_diskpos); + File UNINIT_VAR(next_file); + uint UNINIT_VAR(next_status); + uint UNINIT_VAR(hash_requests); total_found++; found++; diff --git a/mysys/my_getncpus.c b/mysys/my_getncpus.c index 82e87dee2e4..f9db6603924 100644 --- a/mysys/my_getncpus.c +++ b/mysys/my_getncpus.c @@ -18,9 +18,10 @@ #include "mysys_priv.h" #include +#ifdef _SC_NPROCESSORS_ONLN + static int ncpus=0; -#ifdef _SC_NPROCESSORS_ONLN int my_getncpus() { if (!ncpus) diff --git a/regex/regexec.c b/regex/regexec.c index 338c1bfa7fe..c0d03335b41 100644 --- a/regex/regexec.c +++ b/regex/regexec.c @@ -117,6 +117,7 @@ size_t nmatch; my_regmatch_t pmatch[]; int eflags; { + char *pstr = (char *) str; register struct re_guts *g = preg->re_g; #ifdef REDEBUG # define GOODFLAGS(f) (f) @@ -133,7 +134,7 @@ int eflags; if ((size_t) g->nstates <= CHAR_BIT*sizeof(states1) && !(eflags®_LARGE)) - return(smatcher(preg->charset, g, (char *)str, nmatch, pmatch, eflags)); + return(smatcher(preg->charset, g, pstr, nmatch, pmatch, eflags)); else - return(lmatcher(preg->charset, g, (char *)str, nmatch, pmatch, eflags)); + return(lmatcher(preg->charset, g, pstr, nmatch, pmatch, eflags)); } diff --git a/sql/debug_sync.cc b/sql/debug_sync.cc index 23a649a89fa..91c850c6009 100644 --- a/sql/debug_sync.cc +++ b/sql/debug_sync.cc @@ -1718,7 +1718,7 @@ static void debug_sync_execute(THD *thd, st_debug_sync_action *action) if (action->execute) { - const char *old_proc_info; + const char *UNINIT_VAR(old_proc_info); action->execute--; diff --git a/sql/handler.cc b/sql/handler.cc index a47a5fd8a3c..1525ca53bca 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -4141,7 +4141,7 @@ int handler::read_multi_range_first(KEY_MULTI_RANGE **found_range_p, */ int handler::read_multi_range_next(KEY_MULTI_RANGE **found_range_p) { - int result; + int UNINIT_VAR(result); DBUG_ENTER("handler::read_multi_range_next"); /* We should not be called after the last call returned EOF. */ diff --git a/sql/slave.cc b/sql/slave.cc index 57d673ea1f4..644aade517c 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -2321,7 +2321,7 @@ static int exec_relay_log_event(THD* thd, Relay_log_info* rli) if (slave_trans_retries) { - int temp_err; + int UNINIT_VAR(temp_err); if (exec_res && (temp_err= has_temporary_error(thd))) { const char *errmsg; diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 702c3d99fda..44ed9e759c6 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -6747,8 +6747,8 @@ int get_part_iter_for_interval_via_mapping(partition_info *part_info, { DBUG_ASSERT(!is_subpart); Field *field= part_info->part_field_array[0]; - uint32 max_endpoint_val; - get_endpoint_func get_endpoint; + uint32 UNINIT_VAR(max_endpoint_val); + get_endpoint_func UNINIT_VAR(get_endpoint); bool can_match_multiple_values; /* is not '=' */ uint field_len= field->pack_length_in_rec(); part_iter->ret_null_part= part_iter->ret_null_part_orig= FALSE; diff --git a/storage/myisam/ft_nlq_search.c b/storage/myisam/ft_nlq_search.c index 5317da78ee4..e185514b9c1 100644 --- a/storage/myisam/ft_nlq_search.c +++ b/storage/myisam/ft_nlq_search.c @@ -63,7 +63,7 @@ static int FT_SUPERDOC_cmp(void* cmp_arg __attribute__((unused)), static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio) { - int subkeys, r; + int UNINIT_VAR(subkeys), r; uint keylen, doc_cnt; FT_SUPERDOC sdoc, *sptr; TREE_ELEMENT *selem; diff --git a/storage/myisam/mi_create.c b/storage/myisam/mi_create.c index 0b4d781379c..42bd8e26a94 100644 --- a/storage/myisam/mi_create.c +++ b/storage/myisam/mi_create.c @@ -38,7 +38,7 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, MI_CREATE_INFO *ci,uint flags) { register uint i,j; - File UNINIT_VAR(dfile),file; + File UNINIT_VAR(dfile), UNINIT_VAR(file); int errpos,save_errno, create_mode= O_RDWR | O_TRUNC; myf create_flag; uint fields,length,max_key_length,packed,pointer,real_length_diff, @@ -73,8 +73,6 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, { DBUG_RETURN(my_errno=HA_WRONG_CREATE_OPTION); } - LINT_INIT(dfile); - LINT_INIT(file); errpos=0; options=0; bzero((uchar*) &share,sizeof(share)); diff --git a/storage/myisammrg/myrg_open.c b/storage/myisammrg/myrg_open.c index 18f8aa8d2c0..4bc3f7a4018 100644 --- a/storage/myisammrg/myrg_open.c +++ b/storage/myisammrg/myrg_open.c @@ -221,7 +221,7 @@ MYRG_INFO *myrg_parent_open(const char *parent_name, int (*callback)(void*, const char*), void *callback_param) { - MYRG_INFO *m_info; + MYRG_INFO *UNINIT_VAR(m_info); int rc; int errpos; int save_errno; diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index 3bfcf3ee233..ed8031b3fc3 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -1175,7 +1175,7 @@ my_bool fetch_n(const char **query_list, unsigned query_count, /* Separate thread query to test some cases */ -static my_bool thread_query(char *query) +static my_bool thread_query(const char *query) { MYSQL *l_mysql; my_bool error; @@ -1197,7 +1197,7 @@ static my_bool thread_query(char *query) goto end; } l_mysql->reconnect= 1; - if (mysql_query(l_mysql, (char *)query)) + if (mysql_query(l_mysql, query)) { fprintf(stderr, "Query failed (%s)\n", mysql_error(l_mysql)); error= 1; @@ -5821,7 +5821,7 @@ static void test_prepare_alter() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); - if (thread_query((char *)"ALTER TABLE test_prep_alter change id id_new varchar(20)")) + if (thread_query("ALTER TABLE test_prep_alter change id id_new varchar(20)")) exit(1); is_null= 1; From 3219886dc20fb4b49f496010e8b999e0e7716398 Mon Sep 17 00:00:00 2001 From: Mats Kindahl Date: Tue, 16 Nov 2010 11:58:39 +0100 Subject: [PATCH 2/4] Bug #58173: Valgrind warning in load_defaults() Memory was allocated for storing path names inside fn_expand(), which were not free:ed anywhere. This patch fixes the problem by storing the path names in statically allocated buffers instead, which is automatically free:ed when the server exits. --- mysys/default.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/mysys/default.c b/mysys/default.c index a57f1150816..75eb4709e1e 100644 --- a/mysys/default.c +++ b/mysys/default.c @@ -68,6 +68,9 @@ const char *my_defaults_file=0; const char *my_defaults_group_suffix=0; const char *my_defaults_extra_file=0; +static char my_defaults_file_buffer[FN_REFLEN]; +static char my_defaults_extra_file_buffer[FN_REFLEN]; + static my_bool defaults_already_read= FALSE; /* Which directories are searched for options (and in which order) */ @@ -152,22 +155,19 @@ static char *remove_end_comment(char *ptr); */ static int -fn_expand(const char *filename, const char **filename_var) +fn_expand(const char *filename, char *result_buf) { - char dir[FN_REFLEN], buf[FN_REFLEN]; + char dir[FN_REFLEN]; const int flags= MY_UNPACK_FILENAME | MY_SAFE_PATH | MY_RELATIVE_PATH; - const char *result_path= NULL; DBUG_ENTER("fn_expand"); - DBUG_PRINT("enter", ("filename: %s, buf: 0x%lx", filename, (unsigned long) buf)); + DBUG_PRINT("enter", ("filename: %s, result_buf: 0x%lx", + filename, (unsigned long) result_buf)); if (my_getwd(dir, sizeof(dir), MYF(0))) DBUG_RETURN(3); DBUG_PRINT("debug", ("dir: %s", dir)); - if (fn_format(buf, filename, dir, NULL, flags) == NULL || - (result_path= my_strdup(buf, MYF(0))) == NULL) + if (fn_format(result_buf, filename, dir, NULL, flags) == NULL) DBUG_RETURN(2); - DBUG_PRINT("return", ("result: %s", result_path)); - DBUG_ASSERT(result_path != NULL); - *filename_var= result_path; + DBUG_PRINT("return", ("result: %s", result_buf)); DBUG_RETURN(0); } @@ -224,16 +224,18 @@ int my_search_option_files(const char *conf_file, int *argc, char ***argv, if (forced_extra_defaults && !defaults_already_read) { - int error= fn_expand(forced_extra_defaults, &my_defaults_extra_file); + int error= fn_expand(forced_extra_defaults, my_defaults_extra_file_buffer); if (error) DBUG_RETURN(error); + my_defaults_extra_file= my_defaults_extra_file_buffer; } if (forced_default_file && !defaults_already_read) { - int error= fn_expand(forced_default_file, &my_defaults_file); + int error= fn_expand(forced_default_file, my_defaults_file_buffer); if (error) DBUG_RETURN(error); + my_defaults_file= my_defaults_file_buffer; } defaults_already_read= TRUE; From aaa370f5d7fa08b4b6c7fb56bd54f84829626e07 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Wed, 17 Nov 2010 07:41:29 -0200 Subject: [PATCH 3/4] Bug#57994: Compiler flag change build error : my_redel.c Use __builtin_stpcpy only if the system supports stpcpy. This is necessary as in some cases a call to stpcpy will be emitted if the built-in can not optimized. --- include/m_string.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/m_string.h b/include/m_string.h index 933da84c336..c963e605501 100644 --- a/include/m_string.h +++ b/include/m_string.h @@ -73,8 +73,8 @@ extern "C" { extern void *(*my_str_malloc)(size_t); extern void (*my_str_free)(void *); -#if MY_GNUC_PREREQ(3, 4) -#define strmov(dest, src) __builtin_stpcpy(dest, src) +#if defined(HAVE_STPCPY) && MY_GNUC_PREREQ(3, 4) +#define strmov(A,B) __builtin_stpcpy((A),(B)) #elif defined(HAVE_STPCPY) #define strmov(A,B) stpcpy((A),(B)) #ifndef stpcpy From 0654c94ca231a7817369056697ed13e9a2ad5b87 Mon Sep 17 00:00:00 2001 From: Tor Didriksen Date: Wed, 17 Nov 2010 16:39:35 +0100 Subject: [PATCH 4/4] Bug #58137 char(0) column cause: my_gcvt: Assertion `width > 0 && to != ((void *)0)' failed --- mysql-test/r/func_math.result | 9 +++++++++ mysql-test/t/func_math.test | 8 ++++++++ sql/field.cc | 9 ++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/func_math.result b/mysql-test/r/func_math.result index bfb3af0afff..835715ac51e 100644 --- a/mysql-test/r/func_math.result +++ b/mysql-test/r/func_math.result @@ -607,3 +607,12 @@ SELECT floor(log10(format(concat_ws(5445796E25, 5306463, 30837), -358821))) as foo; foo 2 +# +# Bug #58137 char(0) column cause: +# my_gcvt: Assertion `width > 0 && to != ((void *)0)' failed +# +CREATE TABLE t1(a char(0)); +INSERT INTO t1 (SELECT -pi()); +Warnings: +Warning 1265 Data truncated for column 'a' at row 1 +DROP TABLE t1; diff --git a/mysql-test/t/func_math.test b/mysql-test/t/func_math.test index efdf7201a40..5d5dea74e28 100644 --- a/mysql-test/t/func_math.test +++ b/mysql-test/t/func_math.test @@ -464,3 +464,11 @@ SELECT -9223372036854775808 MOD -1; --echo # SELECT floor(log10(format(concat_ws(5445796E25, 5306463, 30837), -358821))) as foo; + +--echo # +--echo # Bug #58137 char(0) column cause: +--echo # my_gcvt: Assertion `width > 0 && to != ((void *)0)' failed +--echo # +CREATE TABLE t1(a char(0)); +INSERT INTO t1 (SELECT -pi()); +DROP TABLE t1; diff --git a/sql/field.cc b/sql/field.cc index a9b5fedda2d..e5cae9ea8e3 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -6327,10 +6327,13 @@ int Field_str::store(double nr) ASSERT_COLUMN_MARKED_FOR_WRITE; char buff[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE]; uint local_char_length= field_length / charset()->mbmaxlen; - size_t length; - my_bool error; + size_t length= 0; + my_bool error= (local_char_length == 0); + + // my_gcvt() requires width > 0, and we may have a CHAR(0) column. + if (!error) + length= my_gcvt(nr, MY_GCVT_ARG_DOUBLE, local_char_length, buff, &error); - length= my_gcvt(nr, MY_GCVT_ARG_DOUBLE, local_char_length, buff, &error); if (error) { if (table->in_use->abort_on_warning)