Skip to content

Commit ab49196

Browse files
author
Steinar H. Gunderson
committed
Bug #26696147: REMOVE MY_SNPRINTF
Remove my_snprintf, replacing it with C++11 snprintf everywhere. Fix a myriad of compiler warnings uncovered as a result, several of them real bugs. The old (non-standard) behavior of %s was to stop at the first invalid UTF-8 codepoint. While useful in specific situations, it was also confusing in others (using e.g. a binary string as INTEGER would print out an empty string, instead of showing that there was data in the string), and thus has been replaced with showing question marks for invalid UTF-8. Change-Id: Ica316ff9d32053c6dc018037cd0d1645ab319d45
1 parent 03dbadf commit ab49196

File tree

205 files changed

+1153
-2230
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

205 files changed

+1153
-2230
lines changed

client/mysql.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <math.h>
3838
#include <signal.h>
3939
#include <stdarg.h>
40+
#include <stdio.h>
4041
#include <stdlib.h>
4142
#include <sys/types.h>
4243
#include <time.h>
@@ -54,7 +55,6 @@
5455
#include "my_io.h"
5556
#include "my_loglevel.h"
5657
#include "my_macros.h"
57-
#include "mysql/service_my_snprintf.h"
5858
#include "prealloced_array.h"
5959
#include "typelib.h"
6060
#include "violite.h"
@@ -1358,7 +1358,7 @@ int main(int argc,char *argv[])
13581358

13591359
put_info("Welcome to the MySQL monitor. Commands end with ; or \\g.",
13601360
INFO_INFO);
1361-
my_snprintf((char*) glob_buffer.ptr(), glob_buffer.alloced_length(),
1361+
snprintf((char*) glob_buffer.ptr(), glob_buffer.alloced_length(),
13621362
"Your MySQL connection id is %lu\nServer version: %s\n",
13631363
mysql_thread_id(&mysql), server_version_string(&mysql));
13641364
put_info((char*) glob_buffer.ptr(),INFO_INFO);
@@ -3226,7 +3226,7 @@ void free_hist_patterns()
32263226

32273227
void add_syslog(const char *line) {
32283228
char buff[MAX_SYSLOG_MESSAGE_SIZE];
3229-
my_snprintf(buff, sizeof(buff), "SYSTEM_USER:'%s', MYSQL_USER:'%s', "
3229+
snprintf(buff, sizeof(buff), "SYSTEM_USER:'%s', MYSQL_USER:'%s', "
32303230
"CONNECTION_ID:%lu, DB_SERVER:'%s', DB:'%s', QUERY:'%s'",
32313231
/* use the cached user/sudo_user value. */
32323232
current_os_sudouser ? current_os_sudouser :
@@ -4775,7 +4775,7 @@ com_use(String *buffer MY_ATTRIBUTE((unused)), char *line)
47754775

47764776
if (0 < (warnings= mysql_warning_count(&mysql)))
47774777
{
4778-
my_snprintf(buff, sizeof(buff),
4778+
snprintf(buff, sizeof(buff),
47794779
"Database changed, %u warning%s", warnings,
47804780
warnings > 1 ? "s" : "");
47814781
put_info(buff, INFO_INFO);

client/mysql_secure_installation.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1616
*/
1717

18+
#include <stdio.h>
1819
#include <stdlib.h>
1920
#include <sys/types.h>
2021

@@ -25,7 +26,6 @@
2526
#include "my_inttypes.h"
2627
#include "my_macros.h"
2728
#include "my_shm_defaults.h"
28-
#include "mysql/service_my_snprintf.h"
2929
#include "mysql/service_mysql_alloc.h"
3030
#include "mysqld_error.h"
3131
#include "print_version.h"
@@ -624,7 +624,7 @@ static int get_opt_user_password()
624624
else
625625
{
626626
char prompt[128];
627-
my_snprintf(prompt, sizeof(prompt) - 1,
627+
snprintf(prompt, sizeof(prompt) - 1,
628628
"Enter password for user %s: ", opt_user);
629629
// Request password from user
630630
password= get_tty_password(prompt);
@@ -977,7 +977,7 @@ int main(int argc,char *argv[])
977977
if (plugin_set == 1)
978978
estimate_password_strength(password);
979979

980-
my_snprintf(prompt, sizeof(prompt) - 1,
980+
snprintf(prompt, sizeof(prompt) - 1,
981981
"Change the password for %s ? ((Press y|Y "
982982
"for Yes, any other key for No) : ", opt_user);
983983
reply= get_response(prompt, 'n');

client/mysqlbinlog.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <fcntl.h>
3434
#include <signal.h>
3535
#include <stdarg.h>
36+
#include <stdio.h>
3637
#include <stdlib.h>
3738
#include <time.h>
3839
#include <algorithm>
@@ -47,7 +48,6 @@
4748
#include "my_io.h"
4849
#include "my_macros.h"
4950
#include "my_time.h"
50-
#include "mysql/service_my_snprintf.h"
5151
#include "prealloced_array.h"
5252
#include "print_version.h"
5353
#include "sql/log_event.h"
@@ -2383,7 +2383,7 @@ static Exit_status dump_remote_log_entries(PRINT_EVENT_INFO *print_event_info,
23832383
{
23842384
if (output_file != 0)
23852385
{
2386-
my_snprintf(log_file_name, sizeof(log_file_name), "%s%s",
2386+
snprintf(log_file_name, sizeof(log_file_name), "%s%s",
23872387
output_file, rev->new_log_ident);
23882388
}
23892389
else

0 commit comments

Comments
 (0)