Fix GCC 10.2.0 -Og -fsanitize=undefined -Wformat-overflow

For some reason, adding -fsanitize=undefined (cmake -DWITH_UBSAN=ON)
to the compilation flags will cause even more warnings to be emitted.
The warning was a bogus one:

tests/mysql_client_test.c:8632:22: error: '%d' directive writing between
1 and 11 bytes into a region of size 9 [-Werror=format-overflow=]
 8632 |     sprintf(field, "c%d int", i);
      |                      ^~
tests/mysql_client_test.c:8632:20: note: directive argument
in the range [-2147483648, 999]

The warning does not take into account that the lower bound of the
variable actually is 0. But, we can help the compiler and use an
unsigned variable.
This commit is contained in:
Marko Mäkelä 2020-09-23 12:14:05 +03:00
parent 594c11fffc
commit 0448558a0d

View File

@ -1,5 +1,5 @@
/* Copyright (c) 2002, 2014, Oracle and/or its affiliates.
Copyright (c) 2008, 2017, MariaDB
Copyright (c) 2008, 2020, MariaDB
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
@ -8457,7 +8457,8 @@ static void test_mem_overun()
char buffer[10000], field[10];
MYSQL_STMT *stmt;
MYSQL_RES *field_res;
int rc, i, length;
int rc, length;
unsigned i;
myheader("test_mem_overun");
@ -8471,7 +8472,7 @@ static void test_mem_overun()
strxmov(buffer, "create table t_mem_overun(", NullS);
for (i= 0; i < 1000; i++)
{
sprintf(field, "c%d int", i);
sprintf(field, "c%u int", i);
strxmov(buffer, buffer, field, ", ", NullS);
}
length= strlen(buffer);