Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MDEV-21978 part 2] Enable and Fix GCC -Wformat Checks on my_vsnprintf and Users #3360

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e1aa751
Merge `vsnprintf` `%b`, `%T` & `%M` code into `%s`/`%u`
ParadoxV5 Jun 5, 2024
aa0fc4f
Add `%sQ`, `%sB`, `%uE` & `%sT` to `my_vsnprintf`
ParadoxV5 Jun 15, 2024
3dbbdd1
Make service_my_snprintf.h doc *more professional*
ParadoxV5 Jun 22, 2024
e9080db
`my_vsnprintf` cache `arg_type` from branches
ParadoxV5 Jul 26, 2024
04a29e0
Rename `my_snprintf`’s `%uE` to `%iE`
ParadoxV5 Aug 12, 2024
37725e8
Remove `my_vsnprintf` tests for ``%`s %b %M %T``
ParadoxV5 Jun 25, 2024
64a8256
Allow ABI mismatches temporarily
ParadoxV5 Jun 29, 2024
f8233cc
Tag `my_vsnprintf` with `__attribute__((format))`
ParadoxV5 Jun 29, 2024
1cc2f55
Use `ATTRIBUTE_FORMAT` whereëver available
ParadoxV5 Jul 5, 2024
bc603c3
Use `%u` in `sql/table.cc`’s `my_snprintf`
ParadoxV5 Jul 19, 2024
1c71674
Tag `mysqltest` formatters with `ATTRIBUTE_FORMAT`
ParadoxV5 Jul 30, 2024
e15073b
Tag rest of my_vsnprintf.c fns w/ ATTRIBUTE_FORMAT
ParadoxV5 Jul 31, 2024
265aaad
Tag `my_printf_error` with `ATTRIBUTE_FORMAT`
ParadoxV5 Aug 1, 2024
f1fb7a7
Tag `push_warning_printf` with `ATTRIBUTE_FORMAT`
ParadoxV5 Aug 2, 2024
e992558
Reënable ATTRIBUTE_FORMAT on DBUG_PRINT & t/eprint
ParadoxV5 Aug 5, 2024
5551db3
Tag the `sql/log.h` family with `ATTRIBUTE_FORMAT`
ParadoxV5 Aug 10, 2024
bd19084
Tag the `logger` service with `ATTRIBUTE_FORMAT`
ParadoxV5 Aug 12, 2024
5f3de9e
Tag `myisamdef.h` printers with `ATTRIBUTE_FORMAT`
ParadoxV5 Aug 13, 2024
fcb2cac
Tag ALL `my_error_reporter`s with `ATTRIBUTE_FORMAT`
ParadoxV5 Aug 13, 2024
41618f4
Tag rest of my_vsnprintf users w/ ATTRIBUTE_FORMAT
ParadoxV5 Aug 13, 2024
2abca63
Update ABIs
ParadoxV5 Aug 13, 2024
85b4e9c
Update `errmsg-utf8.txt` re `my_snprintf` suffixes
ParadoxV5 Aug 15, 2024
60c4d18
Update `my_snprintf`’s last loose ends to suffixes
ParadoxV5 Aug 15, 2024
febd787
Remove ``%`s`` `%b` `%M` `%T` from `my_vsnprintf`
ParadoxV5 Aug 16, 2024
fbe8c57
Update to 4016c905cb
ParadoxV5 Oct 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/mysql_upgrade.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ static void find_tool(char *tool_executable_name, const char *tool_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);
}

Expand Down
2 changes: 1 addition & 1 deletion client/mysqlbinlog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ print_use_stmt(PRINT_EVENT_INFO* pinfo, const Query_log_event *ev)
return;

// 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
// of USE stmts by log_event print-functions.
Expand Down
8 changes: 4 additions & 4 deletions client/mysqlcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ static int is_view(const char *table)
int 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))
{
fprintf(stderr, "Failed to %s\n", query);
Expand Down Expand Up @@ -801,7 +801,7 @@ static int fix_table_storage_name(const char *name)

if (strncmp(name, "#mysql50#", 9))
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);

rc= run_query(qbuf, 1);
Expand All @@ -818,7 +818,7 @@ static int fix_database_storage_name(const char *name)

if (strncmp(name, "#mysql50#", 9))
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);
rc= run_query(qbuf, 1);
if (!opt_silent)
Expand Down Expand Up @@ -1027,7 +1027,7 @@ static void insert_table_name(DYNAMIC_ARRAY *arr, char *in, size_t dblen)
{
char buf[NAME_LEN*2+2];
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);
}

Expand Down
11 changes: 7 additions & 4 deletions client/mysqldump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,10 @@ static const char *load_default_groups[]=
0 };
static void ensure_out_dir_exists(const char *db);
static void maybe_exit(int error);
static void die(int error, const char* reason, ...);
static void maybe_die(int error, const char* reason, ...);
static void die(int error, const char* reason, ...)
ATTRIBUTE_FORMAT(printf, 2, 3);
static void maybe_die(int error, const char* reason, ...)
ATTRIBUTE_FORMAT(printf, 2, 3);
static void write_header(FILE *sql_file, const char *db_name);
static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row,
const char *prefix,const char *name,
Expand All @@ -658,7 +660,8 @@ static int dump_all_tablespaces();
static int dump_tablespaces_for_tables(char *db, char **table_names, int tables);
static int dump_tablespaces_for_databases(char** databases);
static int dump_tablespaces(char* ts_where);
static void print_comment(FILE *, my_bool, const char *, ...);
static void print_comment(FILE *, my_bool, const char *, ...)
ATTRIBUTE_FORMAT(printf, 3, 4);


static inline int cmp_database(const char *a, const char *b)
Expand Down Expand Up @@ -1870,7 +1873,7 @@ static int switch_character_set_results(MYSQL *mysql, const char *cs_name)
query_length= my_snprintf(query_buffer,
sizeof (query_buffer),
"SET SESSION character_set_results = '%s'",
(const char *) cs_name);
cs_name);
ParadoxV5 marked this conversation as resolved.
Show resolved Hide resolved

return mysql_real_query(mysql, query_buffer, (ulong)query_length);
}
Expand Down
37 changes: 19 additions & 18 deletions client/mysqltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,9 @@ static void cleanup_and_exit(int exit_code, bool called_from_die);
ATTRIBUTE_NORETURN
static void really_die(const char *msg);
void report_or_die(const char *fmt, ...);
ATTRIBUTE_NORETURN
ATTRIBUTE_NORETURN ATTRIBUTE_FORMAT(printf, 1, 2)
static void die(const char *fmt, ...);
ATTRIBUTE_FORMAT(printf, 3, 0)
static void make_error_message(char *buf, size_t len, const char *fmt, va_list args);
ATTRIBUTE_NORETURN ATTRIBUTE_FORMAT(printf, 1, 2)
void abort_not_supported_test(const char *fmt, ...);
Expand Down Expand Up @@ -1374,7 +1375,7 @@ void check_command_args(struct st_command *command,

/* Check required arg */
if (arg->ds->length == 0 && arg->required)
die("Missing required argument '%s' to command '%.*b'", arg->argname,
die("Missing required argument '%s' to command '%.*sB'", arg->argname,
command->first_word_len, command->query);

}
Expand All @@ -1383,7 +1384,7 @@ void check_command_args(struct st_command *command,
while(ptr <= command->end && *ptr != '#')
{
if (*ptr && *ptr != ' ')
die("Extra argument '%s' passed to '%.*b'",
die("Extra argument '%s' passed to '%.*sB'",
ptr, command->first_word_len, command->query);
ptr++;
}
Expand All @@ -1403,7 +1404,7 @@ void handle_command_error(struct st_command *command, uint error,

if (command->abort_on_error)
{
report_or_die("command \"%.*b\" failed with error: %u my_errno: %d "
report_or_die("command \"%.*sB\" failed with error: %u my_errno: %d "
"errno: %d",
command->first_word_len, command->query, error, my_errno,
sys_errno);
Expand All @@ -1421,7 +1422,7 @@ void handle_command_error(struct st_command *command, uint error,
DBUG_VOID_RETURN;
}
if (command->expected_errors.count > 0)
report_or_die("command \"%.*b\" failed with wrong error: %u "
report_or_die("command \"%.*sB\" failed with wrong error: %u "
"my_errno: %d errno: %d",
command->first_word_len, command->query, error, my_errno,
sys_errno);
Expand All @@ -1430,7 +1431,7 @@ void handle_command_error(struct st_command *command, uint error,
command->expected_errors.err[0].code.errnum != 0)
{
/* Error code we wanted was != 0, i.e. not an expected success */
report_or_die("command \"%.*b\" succeeded - should have failed with "
report_or_die("command \"%.*sB\" succeeded - should have failed with "
"errno %d...",
command->first_word_len, command->query,
command->expected_errors.err[0].code.errnum);
Expand Down Expand Up @@ -2402,7 +2403,7 @@ static int strip_surrounding(char* str, char c1, char c2)
static void strip_parentheses(struct st_command *command)
{
if (strip_surrounding(command->first_argument, '(', ')'))
die("%.*b - argument list started with '%c' must be ended with '%c'",
die("%.*sB - argument list started with '%c' must be ended with '%c'",
command->first_word_len, command->query, '(', ')');
}

Expand Down Expand Up @@ -3061,7 +3062,7 @@ void eval_expr(VAR *v, const char *p, const char **p_end,
/* Make sure there was just a $variable and nothing else */
const char* end= *p_end + 1;
if (end < expected_end && !open_end)
die("Found junk '%.*b' after $variable in expression",
die("Found junk '%.*sB' after $variable in expression",
(int)(expected_end - end - 1), end);

DBUG_VOID_RETURN;
Expand Down Expand Up @@ -3581,10 +3582,10 @@ int do_modify_var(struct st_command *command,
const char *p= command->first_argument;
VAR* v;
if (!*p)
die("Missing argument to %.*b", command->first_word_len,
die("Missing argument to %.*sB", command->first_word_len,
command->query);
if (*p != '$')
die("The argument to %.*b must be a variable (start with $)",
die("The argument to %.*sB must be a variable (start with $)",
command->first_word_len, command->query);
v= var_get(p, &p, 1, 0);
if (! v->is_int)
Expand Down Expand Up @@ -4935,17 +4936,17 @@ void do_sync_with_master2(struct st_command *command, long offset,
information is not initialized, the arguments are
incorrect, or an error has occurred
*/
die("%.*b failed: '%s' returned NULL " \
die("%.*sB failed: '%s' returned NULL " \
"indicating slave SQL thread failure",
command->first_word_len, command->query, query_buf);
}

if (result == -1)
die("%.*b failed: '%s' returned -1 " \
die("%.*sB failed: '%s' returned -1 " \
"indicating timeout after %d seconds",
command->first_word_len, command->query, query_buf, timeout);
else
die("%.*b failed: '%s' returned unknown result :%d",
die("%.*sB failed: '%s' returned unknown result :%d",
command->first_word_len, command->query, query_buf, result);
}

Expand Down Expand Up @@ -5111,17 +5112,17 @@ int do_sleep(struct st_command *command, my_bool real_sleep)
while (my_isspace(charset_info, *p))
p++;
if (!*p)
die("Missing argument to %.*b", command->first_word_len,
die("Missing argument to %.*sB", command->first_word_len,
command->query);
sleep_start= p;
/* Check that arg starts with a digit, not handled by my_strtod */
if (!my_isdigit(charset_info, *sleep_start))
die("Invalid argument to %.*b \"%s\"", command->first_word_len,
die("Invalid argument to %.*sB \"%s\"", command->first_word_len,
command->query, sleep_start);
sleep_val= my_strtod(sleep_start, &sleep_end, &error);
check_eol_junk_line(sleep_end);
if (error)
die("Invalid argument to %.*b \"%s\"", command->first_word_len,
die("Invalid argument to %.*sB \"%s\"", command->first_word_len,
command->query, command->first_argument);
dynstr_free(&ds_sleep);

Expand Down Expand Up @@ -6241,7 +6242,7 @@ void do_connect(struct st_command *command)
rauth= strdup(con_options + sizeof("auth=") - 1);
}
else
die("Illegal option to connect: %.*b",
die("Illegal option to connect: %.*sB",
(int) (end - con_options), con_options);
/* Process next option */
con_options= end;
Expand Down Expand Up @@ -6563,7 +6564,7 @@ void do_block(enum block_cmd cmd, struct st_command* command)

enum block_op operand= find_operand(curr_ptr);
if (operand == ILLEG_OP)
die("Found junk '%.*b' after $variable in condition",
die("Found junk '%.*sB' after $variable in condition",
(int)(expr_end - curr_ptr), curr_ptr);

/* We could silently allow this, but may be confusing */
Expand Down
14 changes: 7 additions & 7 deletions cmake/do_abi_check.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
#
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting fixes should be in separate commits from functional changes.

#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
Expand All @@ -11,7 +11,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA

#
# Rules for checking that the abi/api has not changed.
Expand All @@ -24,7 +24,7 @@
# results in messages in stderr saying that these headers
# were not found. Redirect the stderr output to /dev/null
# to prevent seeing these messages.
# 2) sed the output to
# 2) sed the output to
# 2.1) remove blank lines and lines that begin with "# "
# 2.2) When gcc -E is run on the Mac OS and solaris sparc platforms it
# introduces a line of output that shows up as a difference between
Expand All @@ -46,7 +46,7 @@
# leave a <build directory>/abi_check.out file.
#
# A developer with a justified API change will then do a
# mv <build directory>/abi_check.out include/mysql/plugin.pp
# mv <build directory>/abi_check.out include/mysql/plugin.pp
# to replace the old canons with the new ones.
#

Expand All @@ -57,11 +57,11 @@ FOREACH(file ${ABI_HEADERS})
SET(tmpfile ${BINARY_DIR}/${header_basename}.pp.tmp)

EXECUTE_PROCESS(
COMMAND ${COMPILER}
COMMAND ${COMPILER}
-E -nostdinc -DMYSQL_ABI_CHECK -D__cplusplus
-I${SOURCE_DIR}/include
-I${BINARY_DIR}/include -I${SOURCE_DIR}/include/mysql -I${SOURCE_DIR}/sql
${file}
${file}
ERROR_QUIET OUTPUT_FILE ${tmpfile})
EXECUTE_PROCESS(
COMMAND sed -e "/^# /d"
Expand All @@ -81,7 +81,7 @@ FOREACH(file ${ABI_HEADERS})
IF(ABI_UPDATE)
EXECUTE_PROCESS(COMMAND mv -v ${abi_check_out} ${file}.pp)
ELSE(ABI_UPDATE)
MESSAGE(FATAL_ERROR
MESSAGE(FATAL_ERROR
"ABI check found difference between ${abi_check_out} and ${file}.pp")
ENDIF(ABI_UPDATE)
ENDIF()
Expand Down
3 changes: 2 additions & 1 deletion dbug/dbug.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ static void Indent(CODE_STATE *cs, int indent);
static void DbugFlush(CODE_STATE *);
static void DbugExit(const char *why);
static const char *DbugStrTok(const char *s);
static void DbugVfprintf(FILE *stream, const char* format, va_list args);
static void DbugVfprintf(FILE *stream, const char* format, va_list args)
ATTRIBUTE_FORMAT(printf, 2, 0);

/*
* Miscellaneous printf format strings.
Expand Down
7 changes: 5 additions & 2 deletions extra/comp_err.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,12 +774,15 @@ static ha_checksum checksum_format_specifier(const char* msg)
{
chksum= my_checksum(chksum, p, 1);
switch(*p) {
case 'c':
case 'd':
case 'i':
case 'o':
case 'p':
case 'u':
case 'x':
case 'X':
case 's':
case 'M':
case 'T':
start= 0; /* Not in format specifier anymore */
break;
}
Expand Down
3 changes: 2 additions & 1 deletion include/m_ctype.h
Original file line number Diff line number Diff line change
Expand Up @@ -1780,7 +1780,8 @@ const MY_CONTRACTIONS *my_charset_get_contractions(CHARSET_INFO *cs,
int level);

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.
Expand Down
6 changes: 1 addition & 5 deletions include/my_dbug.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ extern void _db_enter_(const char *_func_, const char *_file_, uint _line_,
struct _db_stack_frame_ *_stack_frame_);
extern void _db_return_(struct _db_stack_frame_ *_stack_frame_);
extern int _db_pargs_(uint _line_,const char *keyword);
extern void _db_doprnt_(const char *format,...)
#ifdef WAITING_FOR_BUGFIX_TO_VSPRINTF
ATTRIBUTE_FORMAT(printf, 1, 2)
#endif
;
extern void _db_doprnt_(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
extern void _db_dump_(uint _line_,const char *keyword,
const unsigned char *memory, size_t length);
extern void _db_end_(void);
Expand Down
6 changes: 4 additions & 2 deletions include/my_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -722,9 +722,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_freopen(const char *path, const char *mode, FILE *stream);
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 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 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);
Expand Down
Loading