Skip to content

Commit 9d91d93

Browse files
author
Tor Didriksen
committed
Bug #26826272: REMOVE GCC 8 WARNINGS [noclose server]
This patch fixes all -Werror warnings of server code built in optimized mode. It also removes _snprintf on windows, snprintf is now C99 standard compliant. Change-Id: Iafa5aa8d968d97bd2e7a3e39dda64bc308a3de31
1 parent 6fc7f3f commit 9d91d93

33 files changed

+344
-461
lines changed

client/mysqlbinlog.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License, version 2.0,
@@ -104,7 +104,7 @@ static bool rewrite_db(char **buf, ulong *buf_size, uint offset_db,
104104
*buf_size - (offset_db + old_db_len));
105105

106106
// Write new_db and new_db_len.
107-
strncpy((*buf) + offset_db, new_db, new_db_len);
107+
memcpy((*buf) + offset_db, new_db, new_db_len);
108108
(*buf)[offset_len] = (char)new_db_len;
109109

110110
// Update event length in header.

client/mysqlslap.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License, version 2.0,
@@ -122,7 +122,6 @@ database, then reporting the timing of each stage.
122122
#ifdef _WIN32
123123
#define srandom srand
124124
#define random rand
125-
#define snprintf _snprintf
126125
#endif
127126

128127
#if defined(_WIN32)

client/mysqltest.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -3696,8 +3696,9 @@ static void do_mkdir(struct st_command *command) {
36963696
void do_force_rmdir(struct st_command *command, DYNAMIC_STRING *ds_dirname) {
36973697
DBUG_ENTER("do_force_rmdir");
36983698

3699-
char dir_name[FN_REFLEN];
3700-
strncpy(dir_name, ds_dirname->str, sizeof(dir_name));
3699+
char dir_name[FN_REFLEN + 1];
3700+
strncpy(dir_name, ds_dirname->str, sizeof(dir_name) - 1);
3701+
dir_name[FN_REFLEN] = '\0';
37013702

37023703
/* Note that my_dir sorts the list if not given any flags */
37033704
MY_DIR *dir_info = my_dir(ds_dirname->str, MYF(MY_DONT_SORT | MY_WANT_STAT));

libbinlogevents/src/control_events.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ Format_description_event::Format_description_event(uint8_t binlog_ver,
9191
help in getting rid of the valgrind errors.
9292
*/
9393
memset(server_version, 0, ST_SERVER_VER_LEN);
94-
strncpy(server_version, server_ver, ST_SERVER_VER_LEN);
94+
snprintf(server_version, ST_SERVER_VER_LEN, "%.*s", ST_SERVER_VER_LEN - 1,
95+
server_ver);
9596
if (binary_log_debug::debug_pretend_version_50034_in_binlog)
9697
strcpy(server_version, "5.0.34");
9798
common_header_len = LOG_EVENT_HEADER_LEN;

mysql-test/lib/My/SafeProcess/safe_kill_win.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -48,8 +48,8 @@ int main(int argc, const char **argv) {
4848
}
4949
pid = atoi(argv[1]);
5050

51-
_snprintf(safe_process_name, sizeof(safe_process_name), "safe_process[%d]",
52-
pid);
51+
snprintf(safe_process_name, sizeof(safe_process_name), "safe_process[%d]",
52+
pid);
5353

5454
/* Open the event to signal */
5555
while ((shutdown_event = OpenEvent(EVENT_MODIFY_STATE, FALSE,

mysql-test/lib/My/SafeProcess/safe_process_win.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ int main(int argc, const char **argv) {
173173
arg = argv[j];
174174
if (strchr(arg, ' ') && arg[0] != '\"' && arg[strlen(arg)] != '\"') {
175175
/* Quote arg that contains spaces and are not quoted already */
176-
to += _snprintf(to, child_args + sizeof(child_args) - to, "\"%s\" ",
177-
arg);
176+
to += snprintf(to, child_args + sizeof(child_args) - to, "\"%s\" ",
177+
arg);
178178
} else {
179-
to += _snprintf(to, child_args + sizeof(child_args) - to, "%s ", arg);
179+
to += snprintf(to, child_args + sizeof(child_args) - to, "%s ", arg);
180180
}
181181
}
182182
break;

mysys/stacktrace.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,9 @@ void my_write_core(int unused) {
485485
// representation of DWORD value + 4 bytes for .dmp suffix +
486486
// 1 byte for termitated \0. Such size of output buffer guarantees
487487
// that there is enough space to place a result of string formatting
488-
// performed by _snprintf().
489-
_snprintf(dump_fname, sizeof(dump_fname), "%s.%u.dmp", module_name,
490-
GetCurrentProcessId());
488+
// performed by snprintf().
489+
snprintf(dump_fname, sizeof(dump_fname), "%s.%u.dmp", module_name,
490+
GetCurrentProcessId());
491491
}
492492
my_create_minidump(dump_fname, 0, 0);
493493
}

plugin/group_replication/include/recovery_state_transfer.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -109,37 +109,37 @@ class Recovery_state_transfer {
109109

110110
/** Set a SSL trusted certificate authorities file */
111111
void set_recovery_ssl_ca(const char *ssl_ca) {
112-
(void)strncpy(recovery_ssl_ca, ssl_ca, strlen(ssl_ca) + 1);
112+
memcpy(recovery_ssl_ca, ssl_ca, strlen(ssl_ca) + 1);
113113
}
114114

115115
/** Set a folder with SSL trusted CA files */
116116
void set_recovery_ssl_capath(const char *ssl_capath) {
117-
(void)strncpy(recovery_ssl_capath, ssl_capath, strlen(ssl_capath) + 1);
117+
memcpy(recovery_ssl_capath, ssl_capath, strlen(ssl_capath) + 1);
118118
}
119119

120120
/** Set a SSL certificate for connection */
121121
void set_recovery_ssl_cert(const char *ssl_cert) {
122-
(void)strncpy(recovery_ssl_cert, ssl_cert, strlen(ssl_cert) + 1);
122+
memcpy(recovery_ssl_cert, ssl_cert, strlen(ssl_cert) + 1);
123123
}
124124

125125
/** Set a SSL ciphers to be used */
126126
void set_recovery_ssl_cipher(const char *ssl_cipher) {
127-
(void)strncpy(recovery_ssl_cipher, ssl_cipher, strlen(ssl_cipher) + 1);
127+
memcpy(recovery_ssl_cipher, ssl_cipher, strlen(ssl_cipher) + 1);
128128
}
129129

130130
/** Set a SSL key for connections */
131131
void set_recovery_ssl_key(const char *ssl_key) {
132-
(void)strncpy(recovery_ssl_key, ssl_key, strlen(ssl_key) + 1);
132+
memcpy(recovery_ssl_key, ssl_key, strlen(ssl_key) + 1);
133133
}
134134

135135
/** Set a SSL revocation list file*/
136136
void set_recovery_ssl_crl(const char *ssl_crl) {
137-
(void)strncpy(recovery_ssl_crl, ssl_crl, strlen(ssl_crl) + 1);
137+
memcpy(recovery_ssl_crl, ssl_crl, strlen(ssl_crl) + 1);
138138
}
139139

140140
/** Set a folder with SSL revocation list files*/
141141
void set_recovery_ssl_crlpath(const char *ssl_crlpath) {
142-
(void)strncpy(recovery_ssl_crlpath, ssl_crlpath, strlen(ssl_crlpath) + 1);
142+
memcpy(recovery_ssl_crlpath, ssl_crlpath, strlen(ssl_crlpath) + 1);
143143
}
144144

145145
/** Set if recovery shall compare the used hostname against the certificate */
@@ -159,8 +159,8 @@ class Recovery_state_transfer {
159159
/** Set a public key file*/
160160
void set_recovery_public_key_path(const char *public_key_path) {
161161
if (public_key_path != NULL) {
162-
(void)strncpy(recovery_public_key_path, public_key_path,
163-
strlen(public_key_path) + 1);
162+
memcpy(recovery_public_key_path, public_key_path,
163+
strlen(public_key_path) + 1);
164164
}
165165
}
166166

plugin/group_replication/src/plugin.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ int terminate_plugin_modules(bool flag_stop_async_channel,
994994

995995
*error_message =
996996
(char *)my_malloc(PSI_NOT_INSTRUMENTED, err_len + 1, MYF(0));
997-
strncpy(*error_message, err_tmp_arr, err_len);
997+
memcpy(*error_message, err_tmp_arr, err_len + 1);
998998
} else {
999999
char err_tmp_arr[] =
10001000
"Error stopping all replication channels while"

plugin/password_validation/validate_password.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -136,7 +136,7 @@ static bool check_user_name;
136136
static void dictionary_activate(set_type *dict_words) {
137137
time_t start_time;
138138
struct tm tm;
139-
char timebuf[20]; /* "YYYY-MM-DD HH:MM:SS" */
139+
char timebuf[20 * 2]; /* "YYYY-MM-DD HH:MM:SS" */
140140
char *new_ts;
141141

142142
/* fetch the start time */

plugin/test_service_sql_api/test_session_detach.cc

+22-33
Original file line numberDiff line numberDiff line change
@@ -253,34 +253,31 @@ static int sql_get_null(void *ctx) {
253253
}
254254

255255
static int sql_get_integer(void *ctx, longlong value) {
256-
char buffer[1024];
257256
struct st_plugin_ctx *pctx = (struct st_plugin_ctx *)ctx;
258257
DBUG_ENTER("sql_get_integer");
259258
uint row = pctx->num_rows;
260259
uint col = pctx->current_col;
261260
pctx->current_col++;
262261

263-
size_t len = snprintf(buffer, sizeof(buffer), "%lld", value);
264-
265-
strncpy(pctx->sql_str_value[row][col], buffer, len);
262+
size_t len = snprintf(pctx->sql_str_value[row][col],
263+
sizeof(pctx->sql_str_value[row][col]), "%lld", value);
266264
pctx->sql_str_len[row][col] = len;
267265
pctx->sql_int_value[row][col] = value;
268266

269267
DBUG_RETURN(false);
270268
}
271269

272270
static int sql_get_longlong(void *ctx, longlong value, uint is_unsigned) {
273-
char buffer[1024];
274271
struct st_plugin_ctx *pctx = (struct st_plugin_ctx *)ctx;
275272
DBUG_ENTER("sql_get_longlong");
276273
uint row = pctx->num_rows;
277274
uint col = pctx->current_col;
278275
pctx->current_col++;
279276

280-
size_t len =
281-
snprintf(buffer, sizeof(buffer), is_unsigned ? "%llu" : "%lld", value);
277+
size_t len = snprintf(pctx->sql_str_value[row][col],
278+
sizeof(pctx->sql_str_value[row][col]),
279+
is_unsigned ? "%llu" : "%lld", value);
282280

283-
strncpy(pctx->sql_str_value[row][col], buffer, len);
284281
pctx->sql_str_len[row][col] = len;
285282
pctx->sql_longlong_value[row][col] = value;
286283
pctx->sql_is_unsigned[row][col] = is_unsigned;
@@ -289,19 +286,16 @@ static int sql_get_longlong(void *ctx, longlong value, uint is_unsigned) {
289286
}
290287

291288
static int sql_get_decimal(void *ctx, const decimal_t *value) {
292-
char buffer[1024];
293289
struct st_plugin_ctx *pctx = (struct st_plugin_ctx *)ctx;
294290
DBUG_ENTER("sql_get_decimal");
295291
uint row = pctx->num_rows;
296292
uint col = pctx->current_col;
297293
pctx->current_col++;
298294

299-
size_t len = snprintf(buffer, sizeof(buffer), "%s%d.%d(%d)[%s]",
300-
value->sign ? "+" : "-", value->intg, value->frac,
301-
value->len, (char *)value->buf);
302-
303-
strncpy(pctx->sql_str_value[row][col], buffer, len);
304-
295+
size_t len = snprintf(pctx->sql_str_value[row][col],
296+
sizeof(pctx->sql_str_value[row][col]),
297+
"%s%d.%d(%d)[%s]", value->sign ? "+" : "-", value->intg,
298+
value->frac, value->len, (char *)value->buf);
305299
pctx->sql_str_len[row][col] = len;
306300
pctx->sql_decimal_value[row][col].intg = value->intg;
307301
pctx->sql_decimal_value[row][col].frac = value->frac;
@@ -315,16 +309,15 @@ static int sql_get_decimal(void *ctx, const decimal_t *value) {
315309
}
316310

317311
static int sql_get_double(void *ctx, double value, uint32 decimals) {
318-
char buffer[1024];
319312
struct st_plugin_ctx *pctx = (struct st_plugin_ctx *)ctx;
320313
DBUG_ENTER("sql_get_double");
321314
uint row = pctx->num_rows;
322315
uint col = pctx->current_col;
323316
pctx->current_col++;
324317

325-
size_t len = snprintf(buffer, sizeof(buffer), "%3.7g", value);
318+
size_t len = snprintf(pctx->sql_str_value[row][col],
319+
sizeof(pctx->sql_str_value[row][col]), "%3.7g", value);
326320

327-
strncpy(pctx->sql_str_value[row][col], buffer, len);
328321
pctx->sql_str_len[row][col] = len;
329322

330323
pctx->sql_double_value[row][col] = value;
@@ -334,18 +327,16 @@ static int sql_get_double(void *ctx, double value, uint32 decimals) {
334327
}
335328

336329
static int sql_get_date(void *ctx, const MYSQL_TIME *value) {
337-
char buffer[1024];
338330
struct st_plugin_ctx *pctx = (struct st_plugin_ctx *)ctx;
339331
DBUG_ENTER("sql_get_date");
340332
uint row = pctx->num_rows;
341333
uint col = pctx->current_col;
342334
pctx->current_col++;
343335

344336
size_t len =
345-
snprintf(buffer, sizeof(buffer), "%s%4d-%02d-%02d", value->neg ? "-" : "",
346-
value->year, value->month, value->day);
347-
348-
strncpy(pctx->sql_str_value[row][col], buffer, len);
337+
snprintf(pctx->sql_str_value[row][col],
338+
sizeof(pctx->sql_str_value[row][col]), "%s%4d-%02d-%02d",
339+
value->neg ? "-" : "", value->year, value->month, value->day);
349340
pctx->sql_str_len[row][col] = len;
350341

351342
pctx->sql_date_value[row][col].year = value->year;
@@ -362,19 +353,18 @@ static int sql_get_date(void *ctx, const MYSQL_TIME *value) {
362353
}
363354

364355
static int sql_get_time(void *ctx, const MYSQL_TIME *value, uint decimals) {
365-
char buffer[1024];
366356
struct st_plugin_ctx *pctx = (struct st_plugin_ctx *)ctx;
367357
DBUG_ENTER("sql_get_time");
368358
uint row = pctx->num_rows;
369359
uint col = pctx->current_col;
370360
pctx->current_col++;
371361

372362
size_t len = snprintf(
373-
buffer, sizeof(buffer), "%s%02d:%02d:%02d", value->neg ? "-" : "",
363+
pctx->sql_str_value[row][col], sizeof(pctx->sql_str_value[row][col]),
364+
"%s%02d:%02d:%02d", value->neg ? "-" : "",
374365
value->day ? (value->day * 24 + value->hour) : value->hour, value->minute,
375366
value->second);
376367

377-
strncpy(pctx->sql_str_value[row][col], buffer, len);
378368
pctx->sql_str_len[row][col] = len;
379369

380370
pctx->sql_time_value[row][col].year = value->year;
@@ -392,19 +382,17 @@ static int sql_get_time(void *ctx, const MYSQL_TIME *value, uint decimals) {
392382
}
393383

394384
static int sql_get_datetime(void *ctx, const MYSQL_TIME *value, uint decimals) {
395-
char buffer[1024];
396385
struct st_plugin_ctx *pctx = (struct st_plugin_ctx *)ctx;
397386
DBUG_ENTER("sql_get_datetime");
398387
uint row = pctx->num_rows;
399388
uint col = pctx->current_col;
400389
pctx->current_col++;
401390

402-
size_t len =
403-
snprintf(buffer, sizeof(buffer), "%s%4d-%02d-%02d %02d:%02d:%02d",
404-
value->neg ? "-" : "", value->year, value->month, value->day,
405-
value->hour, value->minute, value->second);
391+
size_t len = snprintf(
392+
pctx->sql_str_value[row][col], sizeof(pctx->sql_str_value[row][col]),
393+
"%s%4d-%02d-%02d %02d:%02d:%02d", value->neg ? "-" : "", value->year,
394+
value->month, value->day, value->hour, value->minute, value->second);
406395

407-
strncpy(pctx->sql_str_value[row][col], buffer, len);
408396
pctx->sql_str_len[row][col] = len;
409397

410398
pctx->sql_datetime_value[row][col].year = value->year;
@@ -446,7 +434,8 @@ static void sql_handle_ok(void *ctx, uint server_status,
446434
pctx->warn_count = statement_warn_count;
447435
pctx->affected_rows = affected_rows;
448436
pctx->last_insert_id = last_insert_id;
449-
if (message) strncpy(pctx->message, message, sizeof(pctx->message));
437+
if (message) strncpy(pctx->message, message, sizeof(pctx->message) - 1);
438+
pctx->message[sizeof(pctx->message) - 1] = '\0';
450439

451440
DBUG_VOID_RETURN;
452441
}

0 commit comments

Comments
 (0)