Skip to content

Commit 618afa3

Browse files
ParadoxV5vuvova
authored andcommitted
Tag mysqltest formatters with ATTRIBUTE_FORMAT
Let GCC `-Wformat` check the formats sent to these `my_vsnprintf` users and migrate them from the old `%b` to the new `%sB`
1 parent 5100773 commit 618afa3

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

client/mysqltest.cc

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,9 @@ static void cleanup_and_exit(int exit_code, bool called_from_die);
634634
ATTRIBUTE_NORETURN
635635
static void really_die(const char *msg);
636636
void report_or_die(const char *fmt, ...);
637-
ATTRIBUTE_NORETURN
637+
ATTRIBUTE_NORETURN ATTRIBUTE_FORMAT(printf, 1, 2)
638638
static void die(const char *fmt, ...);
639+
ATTRIBUTE_FORMAT(printf, 3, 0)
639640
static void make_error_message(char *buf, size_t len, const char *fmt, va_list args);
640641
ATTRIBUTE_NORETURN ATTRIBUTE_FORMAT(printf, 1, 2)
641642
void abort_not_supported_test(const char *fmt, ...);
@@ -1371,7 +1372,7 @@ void check_command_args(struct st_command *command,
13711372

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

13771378
}
@@ -1380,7 +1381,7 @@ void check_command_args(struct st_command *command,
13801381
while(ptr <= command->end && *ptr != '#')
13811382
{
13821383
if (*ptr && *ptr != ' ')
1383-
die("Extra argument '%s' passed to '%.*b'",
1384+
die("Extra argument '%s' passed to '%.*sB'",
13841385
ptr, command->first_word_len, command->query);
13851386
ptr++;
13861387
}
@@ -1400,7 +1401,7 @@ void handle_command_error(struct st_command *command, uint error,
14001401

14011402
if (command->abort_on_error)
14021403
{
1403-
report_or_die("command \"%.*b\" failed with error: %u my_errno: %d "
1404+
report_or_die("command \"%.*sB\" failed with error: %u my_errno: %d "
14041405
"errno: %d",
14051406
command->first_word_len, command->query, error, my_errno,
14061407
sys_errno);
@@ -1418,7 +1419,7 @@ void handle_command_error(struct st_command *command, uint error,
14181419
DBUG_VOID_RETURN;
14191420
}
14201421
if (command->expected_errors.count > 0)
1421-
report_or_die("command \"%.*b\" failed with wrong error: %u "
1422+
report_or_die("command \"%.*sB\" failed with wrong error: %u "
14221423
"my_errno: %d errno: %d",
14231424
command->first_word_len, command->query, error, my_errno,
14241425
sys_errno);
@@ -1427,7 +1428,7 @@ void handle_command_error(struct st_command *command, uint error,
14271428
command->expected_errors.err[0].code.errnum != 0)
14281429
{
14291430
/* Error code we wanted was != 0, i.e. not an expected success */
1430-
report_or_die("command \"%.*b\" succeeded - should have failed with "
1431+
report_or_die("command \"%.*sB\" succeeded - should have failed with "
14311432
"errno %d...",
14321433
command->first_word_len, command->query,
14331434
command->expected_errors.err[0].code.errnum);
@@ -2402,7 +2403,7 @@ static int strip_surrounding(char* str, char c1, char c2)
24022403
static void strip_parentheses(struct st_command *command)
24032404
{
24042405
if (strip_surrounding(command->first_argument, '(', ')'))
2405-
die("%.*b - argument list started with '%c' must be ended with '%c'",
2406+
die("%.*sB - argument list started with '%c' must be ended with '%c'",
24062407
command->first_word_len, command->query, '(', ')');
24072408
}
24082409

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

30663067
DBUG_VOID_RETURN;
@@ -3580,10 +3581,10 @@ int do_modify_var(struct st_command *command,
35803581
const char *p= command->first_argument;
35813582
VAR* v;
35823583
if (!*p)
3583-
die("Missing argument to %.*b", command->first_word_len,
3584+
die("Missing argument to %.*sB", command->first_word_len,
35843585
command->query);
35853586
if (*p != '$')
3586-
die("The argument to %.*b must be a variable (start with $)",
3587+
die("The argument to %.*sB must be a variable (start with $)",
35873588
command->first_word_len, command->query);
35883589
v= var_get(p, &p, 1, 0);
35893590
if (! v->is_int)
@@ -4934,17 +4935,17 @@ void do_sync_with_master2(struct st_command *command, long offset,
49344935
information is not initialized, the arguments are
49354936
incorrect, or an error has occurred
49364937
*/
4937-
die("%.*b failed: '%s' returned NULL " \
4938+
die("%.*sB failed: '%s' returned NULL " \
49384939
"indicating slave SQL thread failure",
49394940
command->first_word_len, command->query, query_buf);
49404941
}
49414942

49424943
if (result == -1)
4943-
die("%.*b failed: '%s' returned -1 " \
4944+
die("%.*sB failed: '%s' returned -1 " \
49444945
"indicating timeout after %d seconds",
49454946
command->first_word_len, command->query, query_buf, timeout);
49464947
else
4947-
die("%.*b failed: '%s' returned unknown result :%d",
4948+
die("%.*sB failed: '%s' returned unknown result :%d",
49484949
command->first_word_len, command->query, query_buf, result);
49494950
}
49504951

@@ -5110,17 +5111,17 @@ int do_sleep(struct st_command *command, my_bool real_sleep)
51105111
while (my_isspace(charset_info, *p))
51115112
p++;
51125113
if (!*p)
5113-
die("Missing argument to %.*b", command->first_word_len,
5114+
die("Missing argument to %.*sB", command->first_word_len,
51145115
command->query);
51155116
sleep_start= p;
51165117
/* Check that arg starts with a digit, not handled by my_strtod */
51175118
if (!my_isdigit(charset_info, *sleep_start))
5118-
die("Invalid argument to %.*b \"%s\"", command->first_word_len,
5119+
die("Invalid argument to %.*sB \"%s\"", command->first_word_len,
51195120
command->query, sleep_start);
51205121
sleep_val= my_strtod(sleep_start, &sleep_end, &error);
51215122
check_eol_junk_line(sleep_end);
51225123
if (error)
5123-
die("Invalid argument to %.*b \"%s\"", command->first_word_len,
5124+
die("Invalid argument to %.*sB \"%s\"", command->first_word_len,
51245125
command->query, command->first_argument);
51255126
dynstr_free(&ds_sleep);
51265127

@@ -6240,7 +6241,7 @@ void do_connect(struct st_command *command)
62406241
rauth= strdup(con_options + sizeof("auth=") - 1);
62416242
}
62426243
else
6243-
die("Illegal option to connect: %.*b",
6244+
die("Illegal option to connect: %.*sB",
62446245
(int) (end - con_options), con_options);
62456246
/* Process next option */
62466247
con_options= end;
@@ -6562,7 +6563,7 @@ void do_block(enum block_cmd cmd, struct st_command* command)
65626563

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

65686569
/* We could silently allow this, but may be confusing */

0 commit comments

Comments
 (0)