mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
Tag my_vsnprintf.c
with ATTRIBUTE_FORMAT
[Breaking] Good news: GCC now checks your `my_snprintf` (direct) calls (`-Wformat` was on); Bad news: The build process no longer lets your incorrect formats/arguments sneak past (`-Werror` was also on). As such, this commit also migrates all direct `my_snprintf` calls from the old specifiers to MDEV-21978’s new `-Wformat`-compatible suffixes. The next commits will cover non-direct calls to `my_snprintf`. (I call them “`my_snprintf` descendants”.) This commit does not update the ABI records because there’re more ABI “changes” to come – half a dozen `include/mysql/plugin_*.h.pp`s are now missing the new `__attribute__`s.
This commit is contained in:
committed by
Sergei Golubchik
parent
f3617981ad
commit
5100773ab9
@@ -556,7 +556,7 @@ static void find_tool(char *tool_executable_name, const char *tool_name,
|
|||||||
|
|
||||||
len= (int)(last_fn_libchar - self_name);
|
len= (int)(last_fn_libchar - self_name);
|
||||||
|
|
||||||
my_snprintf(tool_executable_name, FN_REFLEN, "%.*b%c%s",
|
my_snprintf(tool_executable_name, FN_REFLEN, "%.*sB%c%s",
|
||||||
len, self_name, FN_LIBCHAR, tool_name);
|
len, self_name, FN_LIBCHAR, tool_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -631,7 +631,7 @@ print_use_stmt(PRINT_EVENT_INFO* pinfo, const Query_log_event *ev)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// In case of rewrite rule print USE statement for db_to
|
// In case of rewrite rule print USE statement for db_to
|
||||||
my_fprintf(result_file, "use %`s%s\n", db_to, pinfo->delimiter);
|
my_fprintf(result_file, "use %sQ%s\n", db_to, pinfo->delimiter);
|
||||||
|
|
||||||
// Copy the *original* db to pinfo to suppress emitting
|
// Copy the *original* db to pinfo to suppress emitting
|
||||||
// of USE stmts by log_event print-functions.
|
// of USE stmts by log_event print-functions.
|
||||||
|
@@ -551,7 +551,7 @@ static int is_view(const char *table)
|
|||||||
int view;
|
int view;
|
||||||
DBUG_ENTER("is_view");
|
DBUG_ENTER("is_view");
|
||||||
|
|
||||||
my_snprintf(query, sizeof(query), "SHOW CREATE TABLE %`s", table);
|
my_snprintf(query, sizeof(query), "SHOW CREATE TABLE %sQ", table);
|
||||||
if (mysql_query(sock, query))
|
if (mysql_query(sock, query))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to %s\n", query);
|
fprintf(stderr, "Failed to %s\n", query);
|
||||||
@@ -800,7 +800,7 @@ static int fix_table_storage_name(const char *name)
|
|||||||
|
|
||||||
if (strncmp(name, "#mysql50#", 9))
|
if (strncmp(name, "#mysql50#", 9))
|
||||||
DBUG_RETURN(1);
|
DBUG_RETURN(1);
|
||||||
my_snprintf(qbuf, sizeof(qbuf), "RENAME TABLE %`s TO %`s",
|
my_snprintf(qbuf, sizeof(qbuf), "RENAME TABLE %sQ TO %sQ",
|
||||||
name, name + 9);
|
name, name + 9);
|
||||||
|
|
||||||
rc= run_query(qbuf, 1);
|
rc= run_query(qbuf, 1);
|
||||||
@@ -817,7 +817,7 @@ static int fix_database_storage_name(const char *name)
|
|||||||
|
|
||||||
if (strncmp(name, "#mysql50#", 9))
|
if (strncmp(name, "#mysql50#", 9))
|
||||||
DBUG_RETURN(1);
|
DBUG_RETURN(1);
|
||||||
my_snprintf(qbuf, sizeof(qbuf), "ALTER DATABASE %`s UPGRADE DATA DIRECTORY "
|
my_snprintf(qbuf, sizeof(qbuf), "ALTER DATABASE %sQ UPGRADE DATA DIRECTORY "
|
||||||
"NAME", name);
|
"NAME", name);
|
||||||
rc= run_query(qbuf, 1);
|
rc= run_query(qbuf, 1);
|
||||||
if (!opt_silent)
|
if (!opt_silent)
|
||||||
@@ -1026,7 +1026,7 @@ static void insert_table_name(DYNAMIC_ARRAY *arr, char *in, size_t dblen)
|
|||||||
{
|
{
|
||||||
char buf[NAME_LEN*2+2];
|
char buf[NAME_LEN*2+2];
|
||||||
in[dblen]= 0;
|
in[dblen]= 0;
|
||||||
my_snprintf(buf, sizeof(buf), "%`s.%`s", in, in + dblen + 1);
|
my_snprintf(buf, sizeof(buf), "%sQ.%sQ", in, in + dblen + 1);
|
||||||
insert_dynamic(arr, (uchar*) buf);
|
insert_dynamic(arr, (uchar*) buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1776,7 +1776,8 @@ const MY_CONTRACTIONS *my_charset_get_contractions(CHARSET_INFO *cs,
|
|||||||
int level);
|
int level);
|
||||||
|
|
||||||
extern size_t my_vsnprintf_ex(CHARSET_INFO *cs, char *to, size_t n,
|
extern size_t my_vsnprintf_ex(CHARSET_INFO *cs, char *to, size_t n,
|
||||||
const char* fmt, va_list ap);
|
const char* fmt, va_list ap)
|
||||||
|
ATTRIBUTE_FORMAT(printf, 4, 0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Convert a string between two character sets.
|
Convert a string between two character sets.
|
||||||
|
@@ -723,9 +723,11 @@ extern FILE *my_fopen(const char *FileName,int Flags,myf MyFlags);
|
|||||||
extern FILE *my_fdopen(File Filedes,const char *name, int Flags,myf MyFlags);
|
extern FILE *my_fdopen(File Filedes,const char *name, int Flags,myf MyFlags);
|
||||||
extern FILE *my_freopen(const char *path, const char *mode, FILE *stream);
|
extern FILE *my_freopen(const char *path, const char *mode, FILE *stream);
|
||||||
extern int my_fclose(FILE *fd,myf MyFlags);
|
extern int my_fclose(FILE *fd,myf MyFlags);
|
||||||
extern int my_vfprintf(FILE *stream, const char* format, va_list args);
|
extern int my_vfprintf(FILE *stream, const char* format, va_list args)
|
||||||
|
ATTRIBUTE_FORMAT(printf, 2, 0);
|
||||||
extern const char* my_strerror(char *buf, size_t len, int nr);
|
extern const char* my_strerror(char *buf, size_t len, int nr);
|
||||||
extern int my_fprintf(FILE *stream, const char* format, ...);
|
extern int my_fprintf(FILE *stream, const char* format, ...)
|
||||||
|
ATTRIBUTE_FORMAT(printf, 2, 3);
|
||||||
extern File my_fileno(FILE *fd);
|
extern File my_fileno(FILE *fd);
|
||||||
extern int my_chsize(File fd,my_off_t newlength, int filler, myf MyFlags);
|
extern int my_chsize(File fd,my_off_t newlength, int filler, myf MyFlags);
|
||||||
extern int my_chmod(const char *name, mode_t mode, myf my_flags);
|
extern int my_chmod(const char *name, mode_t mode, myf my_flags);
|
||||||
|
@@ -93,10 +93,13 @@ extern "C" {
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <my_attribute.h>
|
||||||
|
|
||||||
extern struct my_snprintf_service_st {
|
extern struct my_snprintf_service_st {
|
||||||
size_t (*my_snprintf_type)(char*, size_t, const char*, ...);
|
size_t (*my_snprintf_type)(char*, size_t, const char*, ...)
|
||||||
size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list);
|
ATTRIBUTE_FORMAT_FPTR(printf, 3, 4);
|
||||||
|
size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list)
|
||||||
|
ATTRIBUTE_FORMAT_FPTR(printf, 3, 0);
|
||||||
} *my_snprintf_service;
|
} *my_snprintf_service;
|
||||||
|
|
||||||
#ifdef MYSQL_DYNAMIC_PLUGIN
|
#ifdef MYSQL_DYNAMIC_PLUGIN
|
||||||
@@ -106,8 +109,10 @@ extern struct my_snprintf_service_st {
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
size_t my_snprintf(char* to, size_t n, const char* fmt, ...);
|
size_t my_snprintf(char* to, size_t n, const char* fmt, ...)
|
||||||
size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap);
|
ATTRIBUTE_FORMAT(printf, 3, 4);
|
||||||
|
size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap)
|
||||||
|
ATTRIBUTE_FORMAT(printf, 3, 0);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -3303,7 +3303,7 @@ static void get_type_name(uint type, unsigned char** meta_ptr,
|
|||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case MYSQL_TYPE_LONG:
|
case MYSQL_TYPE_LONG:
|
||||||
my_snprintf(typestr, typestr_length, "%s", "INT");
|
my_snprintf(typestr, typestr_length, "INT");
|
||||||
break;
|
break;
|
||||||
case MYSQL_TYPE_TINY:
|
case MYSQL_TYPE_TINY:
|
||||||
my_snprintf(typestr, typestr_length, "TINYINT");
|
my_snprintf(typestr, typestr_length, "TINYINT");
|
||||||
@@ -3373,20 +3373,21 @@ static void get_type_name(uint type, unsigned char** meta_ptr,
|
|||||||
break;
|
break;
|
||||||
case MYSQL_TYPE_BLOB:
|
case MYSQL_TYPE_BLOB:
|
||||||
{
|
{
|
||||||
bool is_text= (cs && cs->number != my_charset_bin.number);
|
const char *type_name=
|
||||||
const char *names[5][2] = {
|
(cs && cs->number != my_charset_bin.number) ? "TEXT" : "BLOB";
|
||||||
{"INVALID_BLOB(%d)", "INVALID_TEXT(%d)"},
|
const char *names[5]= {
|
||||||
{"TINYBLOB", "TINYTEXT"},
|
NullS,
|
||||||
{"BLOB", "TEXT"},
|
"TINY",
|
||||||
{"MEDIUMBLOB", "MEDIUMTEXT"},
|
"",
|
||||||
{"LONGBLOB", "LONGTEXT"}
|
"MEDIUM",
|
||||||
|
"LONG"
|
||||||
};
|
};
|
||||||
unsigned char size= **meta_ptr;
|
unsigned char size= **meta_ptr;
|
||||||
|
|
||||||
if (size == 0 || size > 4)
|
if (size == 0 || size > 4)
|
||||||
my_snprintf(typestr, typestr_length, names[0][is_text], size);
|
my_snprintf(typestr, typestr_length, "INVALID_%s(%d)", type_name, size);
|
||||||
else
|
else
|
||||||
my_snprintf(typestr, typestr_length, names[**meta_ptr][is_text]);
|
my_snprintf(typestr, typestr_length, "%s%s", names[size], type_name);
|
||||||
|
|
||||||
(*meta_ptr)++;
|
(*meta_ptr)++;
|
||||||
}
|
}
|
||||||
@@ -3423,7 +3424,7 @@ static void get_type_name(uint type, unsigned char** meta_ptr,
|
|||||||
"MULTILINESTRING", "MULTIPOLYGON", "GEOMETRYCOLLECTION"
|
"MULTILINESTRING", "MULTIPOLYGON", "GEOMETRYCOLLECTION"
|
||||||
};
|
};
|
||||||
if (geometry_type < 8)
|
if (geometry_type < 8)
|
||||||
my_snprintf(typestr, typestr_length, names[geometry_type]);
|
my_snprintf(typestr, typestr_length, "%s", names[geometry_type]);
|
||||||
else
|
else
|
||||||
my_snprintf(typestr, typestr_length, "INVALID_GEOMETRY_TYPE(%u)",
|
my_snprintf(typestr, typestr_length, "INVALID_GEOMETRY_TYPE(%u)",
|
||||||
geometry_type);
|
geometry_type);
|
||||||
|
@@ -711,7 +711,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
|
|||||||
protocol->store(&table_name, system_charset_info);
|
protocol->store(&table_name, system_charset_info);
|
||||||
protocol->store(operator_name, system_charset_info);
|
protocol->store(operator_name, system_charset_info);
|
||||||
protocol->store(&error_clex_str, system_charset_info);
|
protocol->store(&error_clex_str, system_charset_info);
|
||||||
length= my_snprintf(buff, sizeof(buff),
|
length= my_snprintf(buff, sizeof(buff), "%s",
|
||||||
ER_THD(thd, ER_PARTITION_DOES_NOT_EXIST));
|
ER_THD(thd, ER_PARTITION_DOES_NOT_EXIST));
|
||||||
protocol->store(buff, length, system_charset_info);
|
protocol->store(buff, length, system_charset_info);
|
||||||
if(protocol->write())
|
if(protocol->write())
|
||||||
|
@@ -1237,7 +1237,7 @@ update_binlog:
|
|||||||
if (ha_table_exists(thd, &tbl->db, &tbl->table_name))
|
if (ha_table_exists(thd, &tbl->db, &tbl->table_name))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
tbl_name_len= my_snprintf(quoted_name, sizeof(quoted_name), "%`s",
|
tbl_name_len= my_snprintf(quoted_name, sizeof(quoted_name), "%sQ",
|
||||||
tbl->table_name.str);
|
tbl->table_name.str);
|
||||||
tbl_name_len++; /* +1 for the comma */
|
tbl_name_len++; /* +1 for the comma */
|
||||||
if (query_pos + tbl_name_len + 1 >= query_end)
|
if (query_pos + tbl_name_len + 1 >= query_end)
|
||||||
|
@@ -1070,7 +1070,7 @@ static int show_func_example(MYSQL_THD thd, struct st_mysql_show_var *var,
|
|||||||
var->value= buf; // it's of SHOW_VAR_FUNC_BUFF_SIZE bytes
|
var->value= buf; // it's of SHOW_VAR_FUNC_BUFF_SIZE bytes
|
||||||
my_snprintf(buf, SHOW_VAR_FUNC_BUFF_SIZE,
|
my_snprintf(buf, SHOW_VAR_FUNC_BUFF_SIZE,
|
||||||
"enum_var is %lu, ulong_var is %lu, int_var is %d, "
|
"enum_var is %lu, ulong_var is %lu, int_var is %d, "
|
||||||
"double_var is %f, %.6b", // %b is a MariaDB/MySQL extension
|
"double_var is %f, %.6sB", // %sB is a MariaDB extension
|
||||||
srv_enum_var, srv_ulong_var, THDVAR(thd, int_var),
|
srv_enum_var, srv_ulong_var, THDVAR(thd, int_var),
|
||||||
srv_double_var, "really");
|
srv_double_var, "really");
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user