mirror of
https://github.com/MariaDB/server.git
synced 2025-01-30 02:30:06 +01:00
Bug #2717: include/my_global.h mis-defines __attribute__
Fix when __attribute__() is stubbed out, add ATTRIBUTE_FORMAT() for specifying __attribute__((format(...))) safely, make more use of the format attribute, and fix some of the warnings that this turns up (plus a bonus unrelated one). include/m_ctype.h: Add ATTRIBUTE_FORMAT to printf-like functions. include/m_string.h: Add ATTRIBUTE_FORMAT to my_snprintf() declaration. include/my_global.h: Fix neutering of __attribute__() on old versions of GCC and non-GCC compilers. Add ATTRIBUTE_FORMAT() macro for setting __attribute_((format(...)), since it is available from different versions of gcc and g++. include/my_sys.h: Add ATTRIBUTE_FORMAT() to my_printf_error declaration sql/item_subselect.cc: Silence warning about members being initialized out-of-order sql/item_timefunc.cc: Fix format specifier in snprintf() calls with milliseconds sql/mysql_priv.h: Add ATTRIBUTE_FORMAT to printf-like functions. sql/mysqld.cc: Fix various format specifiers Make sure that method_conv is always set by myisam_stats_method sql/opt_range.cc: Cast pointers to correct type for %lx sql/set_var.cc: Fix __attribute__((unused)) (missing inner set of parens) sql/slave.cc: Fix format specifier sql/slave.h: Add ATTRIBUTE_FORMAT to slave_print_error() declaration. sql/sql_acl.cc: Fix number of arguments passed for formatting, and fix acl_host_or_ip being passed instead of just the hostname. sql/sql_class.h: Add ATTRIBUTE_FORMAT to MYSQL_LOG::write().
This commit is contained in:
parent
dba52b539a
commit
915bdfbea8
14 changed files with 64 additions and 38 deletions
|
@ -175,7 +175,7 @@ typedef struct my_charset_handler_st
|
||||||
|
|
||||||
/* Charset dependant snprintf() */
|
/* Charset dependant snprintf() */
|
||||||
int (*snprintf)(struct charset_info_st *, char *to, uint n, const char *fmt,
|
int (*snprintf)(struct charset_info_st *, char *to, uint n, const char *fmt,
|
||||||
...);
|
...) ATTRIBUTE_FORMAT(printf, 4, 5);
|
||||||
int (*long10_to_str)(struct charset_info_st *, char *to, uint n, int radix,
|
int (*long10_to_str)(struct charset_info_st *, char *to, uint n, int radix,
|
||||||
long int val);
|
long int val);
|
||||||
int (*longlong10_to_str)(struct charset_info_st *, char *to, uint n,
|
int (*longlong10_to_str)(struct charset_info_st *, char *to, uint n,
|
||||||
|
@ -300,7 +300,8 @@ int my_wc_mb_8bit(CHARSET_INFO *cs,my_wc_t wc, uchar *s, uchar *e);
|
||||||
ulong my_scan_8bit(CHARSET_INFO *cs, const char *b, const char *e, int sq);
|
ulong my_scan_8bit(CHARSET_INFO *cs, const char *b, const char *e, int sq);
|
||||||
|
|
||||||
int my_snprintf_8bit(struct charset_info_st *, char *to, uint n,
|
int my_snprintf_8bit(struct charset_info_st *, char *to, uint n,
|
||||||
const char *fmt, ...);
|
const char *fmt, ...)
|
||||||
|
ATTRIBUTE_FORMAT(printf, 4, 5);
|
||||||
|
|
||||||
long my_strntol_8bit(CHARSET_INFO *, const char *s, uint l, int base,
|
long my_strntol_8bit(CHARSET_INFO *, const char *s, uint l, int base,
|
||||||
char **e, int *err);
|
char **e, int *err);
|
||||||
|
|
|
@ -247,7 +247,8 @@ extern ulonglong strtoull(const char *str, char **ptr, int base);
|
||||||
|
|
||||||
extern int my_vsnprintf( char *str, size_t n,
|
extern int my_vsnprintf( char *str, size_t n,
|
||||||
const char *format, va_list ap );
|
const char *format, va_list ap );
|
||||||
extern int my_snprintf(char* to, size_t n, const char* fmt, ...);
|
extern int my_snprintf(char *to, size_t n, const char *fmt, ...)
|
||||||
|
ATTRIBUTE_FORMAT(printf, 3, 4);
|
||||||
|
|
||||||
#if defined(__cplusplus) && !defined(OS2)
|
#if defined(__cplusplus) && !defined(OS2)
|
||||||
}
|
}
|
||||||
|
|
|
@ -414,14 +414,34 @@ typedef unsigned short ushort;
|
||||||
#define function_volatile volatile
|
#define function_volatile volatile
|
||||||
#define my_reinterpret_cast(A) reinterpret_cast<A>
|
#define my_reinterpret_cast(A) reinterpret_cast<A>
|
||||||
#define my_const_cast(A) const_cast<A>
|
#define my_const_cast(A) const_cast<A>
|
||||||
|
# ifndef GCC_VERSION
|
||||||
|
# define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
|
||||||
|
# endif
|
||||||
#elif !defined(my_reinterpret_cast)
|
#elif !defined(my_reinterpret_cast)
|
||||||
#define my_reinterpret_cast(A) (A)
|
#define my_reinterpret_cast(A) (A)
|
||||||
#define my_const_cast(A) (A)
|
#define my_const_cast(A) (A)
|
||||||
#endif
|
#endif
|
||||||
#if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__) || __GNUC__ == 2 && __GNUC_MINOR__ < 8)
|
|
||||||
|
/*
|
||||||
|
Disable __attribute__() on GCC < 2.7 and non-GCC compilers
|
||||||
|
*/
|
||||||
|
#if !defined(__attribute__) && (!defined(__GNUC__) || GCC_VERSION < 2007)
|
||||||
#define __attribute__(A)
|
#define __attribute__(A)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
__attribute__((format(...))) is only supported in gcc >= 2.8 and g++ >= 3.4
|
||||||
|
*/
|
||||||
|
#ifndef ATTRIBUTE_FORMAT
|
||||||
|
# if defined(__GNUC__) && \
|
||||||
|
((!defined(__cplusplus__) && GCC_VERSION >= 2008) || \
|
||||||
|
GCC_VERSION >= 3004)
|
||||||
|
# define ATTRIBUTE_FORMAT(style, m, n) __attribute__((format(style, m, n)))
|
||||||
|
# else
|
||||||
|
# define ATTRIBUTE_FORMAT(style, m, n)
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/* From old s-system.h */
|
/* From old s-system.h */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -588,8 +588,8 @@ extern int my_chsize(File fd,my_off_t newlength, int filler, myf MyFlags);
|
||||||
extern int my_sync(File fd, myf my_flags);
|
extern int my_sync(File fd, myf my_flags);
|
||||||
extern int my_error _VARARGS((int nr,myf MyFlags, ...));
|
extern int my_error _VARARGS((int nr,myf MyFlags, ...));
|
||||||
extern int my_printf_error _VARARGS((uint my_err, const char *format,
|
extern int my_printf_error _VARARGS((uint my_err, const char *format,
|
||||||
myf MyFlags, ...)
|
myf MyFlags, ...))
|
||||||
__attribute__ ((format (printf, 2, 4))));
|
ATTRIBUTE_FORMAT(printf, 2, 4);
|
||||||
extern int my_message(uint my_err, const char *str,myf MyFlags);
|
extern int my_message(uint my_err, const char *str,myf MyFlags);
|
||||||
extern int my_message_no_curses(uint my_err, const char *str,myf MyFlags);
|
extern int my_message_no_curses(uint my_err, const char *str,myf MyFlags);
|
||||||
extern int my_message_curses(uint my_err, const char *str,myf MyFlags);
|
extern int my_message_curses(uint my_err, const char *str,myf MyFlags);
|
||||||
|
|
|
@ -545,7 +545,7 @@ Item_allany_subselect::Item_allany_subselect(Item * left_exp,
|
||||||
chooser_compare_func_creator fc,
|
chooser_compare_func_creator fc,
|
||||||
st_select_lex *select_lex,
|
st_select_lex *select_lex,
|
||||||
bool all_arg)
|
bool all_arg)
|
||||||
:Item_in_subselect(), all(all_arg), func_creator(fc)
|
:Item_in_subselect(), func_creator(fc), all(all_arg)
|
||||||
{
|
{
|
||||||
DBUG_ENTER("Item_in_subselect::Item_in_subselect");
|
DBUG_ENTER("Item_in_subselect::Item_in_subselect");
|
||||||
left_expr= left_exp;
|
left_expr= left_exp;
|
||||||
|
|
|
@ -65,7 +65,7 @@ static bool make_datetime(date_time_format_types format, TIME *ltime,
|
||||||
ltime->hour, ltime->minute, ltime->second);
|
ltime->hour, ltime->minute, ltime->second);
|
||||||
break;
|
break;
|
||||||
case TIME_MICROSECOND:
|
case TIME_MICROSECOND:
|
||||||
length= cs->cset->snprintf(cs, buff, length, "%s%02d:%02d:%02d.%06d",
|
length= cs->cset->snprintf(cs, buff, length, "%s%02d:%02d:%02d.%06ld",
|
||||||
ltime->neg ? "-" : "",
|
ltime->neg ? "-" : "",
|
||||||
ltime->hour, ltime->minute, ltime->second,
|
ltime->hour, ltime->minute, ltime->second,
|
||||||
ltime->second_part);
|
ltime->second_part);
|
||||||
|
@ -82,7 +82,7 @@ static bool make_datetime(date_time_format_types format, TIME *ltime,
|
||||||
break;
|
break;
|
||||||
case DATE_TIME_MICROSECOND:
|
case DATE_TIME_MICROSECOND:
|
||||||
length= cs->cset->snprintf(cs, buff, length,
|
length= cs->cset->snprintf(cs, buff, length,
|
||||||
"%04d-%02d-%02d %02d:%02d:%02d.%06d",
|
"%04d-%02d-%02d %02d:%02d:%02d.%06ld",
|
||||||
ltime->year, ltime->month, ltime->day,
|
ltime->year, ltime->month, ltime->day,
|
||||||
ltime->hour, ltime->minute, ltime->second,
|
ltime->hour, ltime->minute, ltime->second,
|
||||||
ltime->second_part);
|
ltime->second_part);
|
||||||
|
|
|
@ -712,7 +712,8 @@ void mysql_stmt_get_longdata(THD *thd, char *pos, ulong packet_length);
|
||||||
MYSQL_ERROR *push_warning(THD *thd, MYSQL_ERROR::enum_warning_level level, uint code,
|
MYSQL_ERROR *push_warning(THD *thd, MYSQL_ERROR::enum_warning_level level, uint code,
|
||||||
const char *msg);
|
const char *msg);
|
||||||
void push_warning_printf(THD *thd, MYSQL_ERROR::enum_warning_level level,
|
void push_warning_printf(THD *thd, MYSQL_ERROR::enum_warning_level level,
|
||||||
uint code, const char *format, ...);
|
uint code, const char *format, ...)
|
||||||
|
ATTRIBUTE_FORMAT(printf,4,5);
|
||||||
void mysql_reset_errors(THD *thd);
|
void mysql_reset_errors(THD *thd);
|
||||||
my_bool mysqld_show_warnings(THD *thd, ulong levels_to_show);
|
my_bool mysqld_show_warnings(THD *thd, ulong levels_to_show);
|
||||||
|
|
||||||
|
@ -847,10 +848,10 @@ bool init_errmessage(void);
|
||||||
void sql_perror(const char *message);
|
void sql_perror(const char *message);
|
||||||
|
|
||||||
void vprint_msg_to_log(enum loglevel level, const char *format, va_list args);
|
void vprint_msg_to_log(enum loglevel level, const char *format, va_list args);
|
||||||
void sql_print_error(const char *format, ...);
|
void sql_print_error(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
|
||||||
void sql_print_warning(const char *format, ...);
|
void sql_print_warning(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
|
||||||
void sql_print_information(const char *format, ...);
|
void sql_print_information(const char *format, ...)
|
||||||
|
ATTRIBUTE_FORMAT(printf, 1, 2);
|
||||||
|
|
||||||
|
|
||||||
bool fn_format_relative_to_data_home(my_string to, const char *name,
|
bool fn_format_relative_to_data_home(my_string to, const char *name,
|
||||||
|
|
|
@ -952,8 +952,8 @@ extern "C" sig_handler print_signal_warning(int sig)
|
||||||
if (!DBUG_IN_USE)
|
if (!DBUG_IN_USE)
|
||||||
{
|
{
|
||||||
if (global_system_variables.log_warnings)
|
if (global_system_variables.log_warnings)
|
||||||
sql_print_warning("Got signal %d from thread %d",
|
sql_print_warning("Got signal %d from thread %ld",
|
||||||
sig,my_thread_id());
|
sig, my_thread_id());
|
||||||
}
|
}
|
||||||
#ifdef DONT_REMEMBER_SIGNAL
|
#ifdef DONT_REMEMBER_SIGNAL
|
||||||
my_sigset(sig,print_signal_warning); /* int. thread system calls */
|
my_sigset(sig,print_signal_warning); /* int. thread system calls */
|
||||||
|
@ -1443,8 +1443,8 @@ static void server_init(void)
|
||||||
|
|
||||||
if (strlen(mysqld_unix_port) > (sizeof(UNIXaddr.sun_path) - 1))
|
if (strlen(mysqld_unix_port) > (sizeof(UNIXaddr.sun_path) - 1))
|
||||||
{
|
{
|
||||||
sql_print_error("The socket file path is too long (> %d): %s",
|
sql_print_error("The socket file path is too long (> %lu): %s",
|
||||||
sizeof(UNIXaddr.sun_path) - 1, mysqld_unix_port);
|
sizeof(UNIXaddr.sun_path) - 1, mysqld_unix_port);
|
||||||
unireg_abort(1);
|
unireg_abort(1);
|
||||||
}
|
}
|
||||||
if ((unix_sock= socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
|
if ((unix_sock= socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
|
||||||
|
@ -2786,9 +2786,9 @@ static void openssl_lock(int mode, openssl_lock_t *lock, const char *file,
|
||||||
sql_print_error("Fatal: OpenSSL interface problem (mode=0x%x)", mode);
|
sql_print_error("Fatal: OpenSSL interface problem (mode=0x%x)", mode);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
sql_print_error("Fatal: can't %s OpenSSL %s lock", what);
|
sql_print_error("Fatal: can't %s OpenSSL lock", what);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6549,14 +6549,15 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
switch (method-1) {
|
switch (method-1) {
|
||||||
case 0:
|
case 2:
|
||||||
method_conv= MI_STATS_METHOD_NULLS_EQUAL;
|
method_conv= MI_STATS_METHOD_IGNORE_NULLS;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
method_conv= MI_STATS_METHOD_NULLS_NOT_EQUAL;
|
method_conv= MI_STATS_METHOD_NULLS_NOT_EQUAL;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 0:
|
||||||
method_conv= MI_STATS_METHOD_IGNORE_NULLS;
|
default:
|
||||||
|
method_conv= MI_STATS_METHOD_NULLS_EQUAL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
global_system_variables.myisam_stats_method= method_conv;
|
global_system_variables.myisam_stats_method= method_conv;
|
||||||
|
|
|
@ -2513,8 +2513,9 @@ void SEL_ARG::test_use_count(SEL_ARG *root)
|
||||||
ulong count=count_key_part_usage(root,pos->next_key_part);
|
ulong count=count_key_part_usage(root,pos->next_key_part);
|
||||||
if (count > pos->next_key_part->use_count)
|
if (count > pos->next_key_part->use_count)
|
||||||
{
|
{
|
||||||
sql_print_information("Use_count: Wrong count for key at %lx, %lu should be %lu",
|
sql_print_information("Use_count: Wrong count for key at %lx, %lu "
|
||||||
pos,pos->next_key_part->use_count,count);
|
"should be %lu", (long unsigned int)pos,
|
||||||
|
pos->next_key_part->use_count, count);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pos->next_key_part->test_use_count(root);
|
pos->next_key_part->test_use_count(root);
|
||||||
|
@ -2522,7 +2523,7 @@ void SEL_ARG::test_use_count(SEL_ARG *root)
|
||||||
}
|
}
|
||||||
if (e_count != elements)
|
if (e_count != elements)
|
||||||
sql_print_warning("Wrong use count: %u (should be %u) for tree at %lx",
|
sql_print_warning("Wrong use count: %u (should be %u) for tree at %lx",
|
||||||
e_count, elements, (gptr) this);
|
e_count, elements, (long unsigned int) this);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1150,14 +1150,14 @@ static void fix_net_retry_count(THD *thd, enum_var_type type)
|
||||||
thd->net.retry_count=thd->variables.net_retry_count;
|
thd->net.retry_count=thd->variables.net_retry_count;
|
||||||
}
|
}
|
||||||
#else /* HAVE_REPLICATION */
|
#else /* HAVE_REPLICATION */
|
||||||
static void fix_net_read_timeout(THD *thd __attribute__(unused),
|
static void fix_net_read_timeout(THD *thd __attribute__((unused)),
|
||||||
enum_var_type type __attribute__(unused))
|
enum_var_type type __attribute__((unused)))
|
||||||
{}
|
{}
|
||||||
static void fix_net_write_timeout(THD *thd __attribute__(unused),
|
static void fix_net_write_timeout(THD *thd __attribute__((unused)),
|
||||||
enum_var_type type __attribute__(unused))
|
enum_var_type type __attribute__((unused)))
|
||||||
{}
|
{}
|
||||||
static void fix_net_retry_count(THD *thd __attribute__(unused),
|
static void fix_net_retry_count(THD *thd __attribute__((unused)),
|
||||||
enum_var_type type __attribute__(unused))
|
enum_var_type type __attribute__((unused)))
|
||||||
{}
|
{}
|
||||||
#endif /* HAVE_REPLICATION */
|
#endif /* HAVE_REPLICATION */
|
||||||
|
|
||||||
|
|
|
@ -4073,7 +4073,7 @@ static int connect_to_master(THD* thd, MYSQL* mysql, MASTER_INFO* mi,
|
||||||
suppress_warnings= 0;
|
suppress_warnings= 0;
|
||||||
sql_print_error("Slave I/O thread: error %s to master \
|
sql_print_error("Slave I/O thread: error %s to master \
|
||||||
'%s@%s:%d': \
|
'%s@%s:%d': \
|
||||||
Error: '%s' errno: %d retry-time: %d retries: %d",
|
Error: '%s' errno: %d retry-time: %d retries: %lu",
|
||||||
(reconnect ? "reconnecting" : "connecting"),
|
(reconnect ? "reconnecting" : "connecting"),
|
||||||
mi->user,mi->host,mi->port,
|
mi->user,mi->host,mi->port,
|
||||||
mysql_error(mysql), last_errno,
|
mysql_error(mysql), last_errno,
|
||||||
|
|
|
@ -551,7 +551,8 @@ const char *rewrite_db(const char* db, uint32 *new_db_len);
|
||||||
const char *print_slave_db_safe(const char *db);
|
const char *print_slave_db_safe(const char *db);
|
||||||
int check_expected_error(THD* thd, RELAY_LOG_INFO* rli, int error_code);
|
int check_expected_error(THD* thd, RELAY_LOG_INFO* rli, int error_code);
|
||||||
void skip_load_data_infile(NET* net);
|
void skip_load_data_infile(NET* net);
|
||||||
void slave_print_error(RELAY_LOG_INFO* rli, int err_code, const char* msg, ...);
|
void slave_print_error(RELAY_LOG_INFO *rli, int err_code, const char *msg, ...)
|
||||||
|
ATTRIBUTE_FORMAT(printf, 3, 4);
|
||||||
|
|
||||||
void end_slave(); /* clean up */
|
void end_slave(); /* clean up */
|
||||||
void init_master_info_with_options(MASTER_INFO* mi);
|
void init_master_info_with_options(MASTER_INFO* mi);
|
||||||
|
|
|
@ -426,7 +426,7 @@ static my_bool acl_load(THD *thd, TABLE_LIST *tables)
|
||||||
"case that has been forced to lowercase because "
|
"case that has been forced to lowercase because "
|
||||||
"lower_case_table_names is set. It will not be "
|
"lower_case_table_names is set. It will not be "
|
||||||
"possible to remove this privilege using REVOKE.",
|
"possible to remove this privilege using REVOKE.",
|
||||||
db.db, db.user, db.host.hostname, db.host.hostname);
|
db.db, db.user, db.host.hostname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
db.sort=get_sort(3,db.host.hostname,db.db,db.user);
|
db.sort=get_sort(3,db.host.hostname,db.db,db.user);
|
||||||
|
@ -2778,7 +2778,7 @@ static my_bool grant_load(TABLE_LIST *tables)
|
||||||
sql_print_warning("'tables_priv' entry '%s %s@%s' "
|
sql_print_warning("'tables_priv' entry '%s %s@%s' "
|
||||||
"ignored in --skip-name-resolve mode.",
|
"ignored in --skip-name-resolve mode.",
|
||||||
mem_check->tname, mem_check->user,
|
mem_check->tname, mem_check->user,
|
||||||
mem_check->host);
|
mem_check->host.hostname);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,7 +145,7 @@ public:
|
||||||
bool no_auto_events_arg, ulong max_size);
|
bool no_auto_events_arg, ulong max_size);
|
||||||
void new_file(bool need_lock= 1);
|
void new_file(bool need_lock= 1);
|
||||||
bool write(THD *thd, enum enum_server_command command,
|
bool write(THD *thd, enum enum_server_command command,
|
||||||
const char *format,...);
|
const char *format, ...) ATTRIBUTE_FORMAT(printf, 4, 5);
|
||||||
bool write(THD *thd, const char *query, uint query_length,
|
bool write(THD *thd, const char *query, uint query_length,
|
||||||
time_t query_start=0);
|
time_t query_start=0);
|
||||||
bool write(Log_event* event_info); // binary log write
|
bool write(Log_event* event_info); // binary log write
|
||||||
|
|
Loading…
Add table
Reference in a new issue