Skip to content
/ server Public

Commit 0417b45

Browse files
author
gkodinov
committed
MDEV-38499: cmake and compile warnings on MacOSX when
compiling mariadb from a git tree Fixed sprintf deprecation warnings compiling on MacOSX. Replaced some sprintf calls with equivalent snprintf calls, enough so that "normal" compile on MacOSX (as documented in the docs) completes without warnings.
1 parent 366de0a commit 0417b45

File tree

21 files changed

+110
-79
lines changed

21 files changed

+110
-79
lines changed

client/mysqladmin.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
684684
}
685685
if (maybe_disable_binlog(mysql))
686686
return -1;
687-
sprintf(buff,"create database `%.*s`",FN_REFLEN,argv[1]);
687+
snprintf(buff, sizeof(buff), "create database `%.*s`",FN_REFLEN,argv[1]);
688688
if (mysql_query(mysql,buff))
689689
{
690690
my_printf_error(0,"CREATE DATABASE failed; error: '%-.200s'",
@@ -725,7 +725,7 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
725725

726726
if (opt_shutdown_wait_for_slaves)
727727
{
728-
sprintf(buff, "SHUTDOWN WAIT FOR ALL SLAVES");
728+
snprintf(buff, sizeof(buff), "SHUTDOWN WAIT FOR ALL SLAVES");
729729
if (mysql_query(mysql, buff))
730730
{
731731
my_printf_error(0, "%s failed; error: '%-.200s'",
@@ -1128,7 +1128,7 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
11281128
}
11291129
else
11301130
crypted_pw[0]=0; /* No password */
1131-
sprintf(buff,"set password='%s',sql_log_off=0",crypted_pw);
1131+
snprintf(buff, sizeof(buff), "set password='%s',sql_log_off=0",crypted_pw);
11321132

11331133
if (mysql_query(mysql,"set sql_log_off=1"))
11341134
{
@@ -1373,7 +1373,7 @@ static int drop_db(MYSQL *mysql, const char *db)
13731373
return -1;
13741374
}
13751375
}
1376-
sprintf(name_buff,"drop database `%.*s`",FN_REFLEN,db);
1376+
snprintf(name_buff,sizeof(name_buff), "drop database `%.*s`",FN_REFLEN,db);
13771377
if (mysql_query(mysql,name_buff))
13781378
{
13791379
my_printf_error(0, "DROP DATABASE %s failed;\nerror: '%s'", error_flags,

client/mysqlbinlog.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,17 +308,18 @@ class Load_log_processor
308308
filename. The numerical suffix will be written to this position.
309309
Note that there must be a least five bytes of allocated memory
310310
after file_name_end.
311+
@param[in] file_name_end_size Size of the memory area pointed to file_name_end.
311312
312313
@retval -1 Error (can't find new filename).
313314
@retval >=0 Found file.
314315
*/
315-
File create_unique_file(char *filename, char *file_name_end)
316+
File create_unique_file(char *filename, char *file_name_end, size_t file_name_end_size)
316317
{
317318
File res;
318319
/* If we have to try more than 1000 times, something is seriously wrong */
319320
for (uint version= 0; version<1000; version++)
320321
{
321-
sprintf(file_name_end,"-%x",version);
322+
snprintf(file_name_end, file_name_end_size,"-%x",version);
322323
if ((res= my_create(filename,0,
323324
O_CREAT|O_EXCL|O_BINARY|O_WRONLY,MYF(0)))!=-1)
324325
return res;
@@ -440,9 +441,9 @@ Exit_status Load_log_processor::process_first_event(const char *bname,
440441
ptr= fname + target_dir_name_len;
441442
memcpy(ptr,bname,blen);
442443
ptr+= blen;
443-
ptr+= sprintf(ptr, "-%x", file_id);
444+
ptr+= snprintf(ptr, full_len - (ptr - fname), "-%x", file_id);
444445

445-
if ((file= create_unique_file(fname,ptr)) < 0)
446+
if ((file= create_unique_file(fname,ptr,full_len - (ptr - fname))) < 0)
446447
{
447448
error("Could not construct local filename %s%s.",
448449
target_dir_name,bname);
@@ -2546,7 +2547,7 @@ static Exit_status check_master_version()
25462547
char buf[256];
25472548
rpl_gtid *start_gtid= &start_gtids[gtid_idx];
25482549

2549-
sprintf(buf, "%u-%u-%llu",
2550+
snprintf(buf, sizeof(buf), "%u-%u-%llu",
25502551
start_gtid->domain_id, start_gtid->server_id,
25512552
start_gtid->seq_no);
25522553
query_str.append(buf, strlen(buf));

client/mysqldump.cc

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6352,7 +6352,7 @@ const char fmt_gtid_pos[]= "%sSET GLOBAL gtid_slave_pos='%s';\n";
63526352

63536353
static int do_show_master_status(MYSQL *mysql_con, int consistent_binlog_pos,
63546354
int have_mariadb_gtid, int use_gtid,
6355-
char *set_gtid_pos)
6355+
char *set_gtid_pos, size_t set_gtid_pos_size)
63566356
{
63576357
MYSQL_ROW row;
63586358
MYSQL_RES *UNINIT_VAR(master);
@@ -6427,7 +6427,7 @@ static int do_show_master_status(MYSQL *mysql_con, int consistent_binlog_pos,
64276427
"CHANGE-MASTER settings to the slave gtid state is printed "
64286428
"later in the file.\n");
64296429
}
6430-
sprintf(set_gtid_pos, fmt_gtid_pos,
6430+
snprintf(set_gtid_pos, set_gtid_pos_size, fmt_gtid_pos,
64316431
(!use_gtid ? "-- " : comment_prefix), gtid_pos);
64326432
}
64336433

@@ -6479,7 +6479,7 @@ static int do_stop_slave_sql(MYSQL *mysql_con)
64796479
{
64806480
char query[160];
64816481
if (multi_source)
6482-
sprintf(query, "STOP SLAVE '%.80s' SQL_THREAD", row[0]);
6482+
snprintf(query, sizeof(query), "STOP SLAVE '%.80s' SQL_THREAD", row[0]);
64836483
else
64846484
strmov(query, "STOP SLAVE SQL_THREAD");
64856485

@@ -6518,7 +6518,8 @@ static int add_slave_statements(void)
65186518
}
65196519

65206520
static int do_show_slave_status(MYSQL *mysql_con, int have_mariadb_gtid,
6521-
int use_gtid, char* set_gtid_pos)
6521+
int use_gtid, char* set_gtid_pos,
6522+
size_t set_gtid_pos_size)
65226523
{
65236524
MYSQL_RES *UNINIT_VAR(slave);
65246525
MYSQL_ROW row;
@@ -6563,7 +6564,8 @@ static int do_show_slave_status(MYSQL *mysql_con, int have_mariadb_gtid,
65636564
"\n-- A corresponding to the below dump-slave "
65646565
"CHANGE-MASTER settings to the slave gtid state is printed "
65656566
"later in the file.\n");
6566-
sprintf(set_gtid_pos, fmt_gtid_pos, gtid_comment_prefix, gtid_pos);
6567+
snprintf(set_gtid_pos, set_gtid_pos_size,
6568+
fmt_gtid_pos, gtid_comment_prefix, gtid_pos);
65676569
}
65686570
if (use_gtid)
65696571
print_comment(md_result_file, 0,
@@ -6639,7 +6641,8 @@ static int do_start_slave_sql(MYSQL *mysql_con)
66396641
{
66406642
char query[160];
66416643
if (multi_source)
6642-
sprintf(query, "START SLAVE '%.80s' SQL_THREAD", row[0]);
6644+
snprintf(query, sizeof(query),
6645+
"START SLAVE '%.80s' SQL_THREAD", row[0]);
66436646
else
66446647
strmov(query, "START SLAVE SQL_THREAD");
66456648

@@ -7738,11 +7741,13 @@ int main(int argc, char **argv)
77387741

77397742
if (opt_master_data && do_show_master_status(mysql, consistent_binlog_pos,
77407743
have_mariadb_gtid,
7741-
opt_use_gtid, master_set_gtid_pos))
7744+
opt_use_gtid, master_set_gtid_pos,
7745+
sizeof(master_set_gtid_pos)))
77427746
goto err;
77437747
if (opt_slave_data && do_show_slave_status(mysql,
77447748
have_mariadb_gtid,
7745-
opt_use_gtid, slave_set_gtid_pos))
7749+
opt_use_gtid, slave_set_gtid_pos,
7750+
sizeof(slave_set_gtid_pos)))
77467751
goto err;
77477752
if (opt_single_transaction && do_unlock_tables(mysql)) /* unlock but no commit! */
77487753
goto err;

client/mysqlimport.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,8 @@ int table_load_params::load_data(MYSQL *mysql)
727727
}
728728
mysql_real_escape_string(mysql, escaped_name, hard_path,
729729
(unsigned long) strlen(hard_path));
730-
sprintf(sql_statement, "LOAD DATA %s %s INFILE '%s'",
730+
snprintf(sql_statement, sizeof(sql_statement),
731+
"LOAD DATA %s %s INFILE '%s'",
731732
opt_low_priority ? "LOW_PRIORITY" : "",
732733
opt_local_file ? "LOCAL" : "", escaped_name);
733734

extra/mariabackup/backup_copy.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,7 @@ copy_back()
17531753

17541754
for (uint i = 1; i <= TRX_SYS_MAX_UNDO_SPACES; i++) {
17551755
char filename[20];
1756-
sprintf(filename, "undo%03u", i);
1756+
snprintf(filename, sizeof(filename), "undo%03u", i);
17571757
if (!file_exists(filename)) {
17581758
break;
17591759
}

extra/mariabackup/backup_mysql.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ xb_mysql_connect()
148148
char mysql_port_str[std::numeric_limits<int>::digits10 + 3];
149149
const char *user= opt_user ? opt_user : get_os_user();
150150

151-
sprintf(mysql_port_str, "%d", opt_port);
151+
snprintf(mysql_port_str, sizeof(mysql_port_str), "%d", opt_port);
152152

153153
if (connection == NULL) {
154154
msg("Failed to init MariaDB struct: %s.",

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ int main(int argc, char* const argv[] )
237237
sigaction(SIGCHLD, &sa,NULL);
238238
sigaction(SIGABRT, &sa_abort,NULL);
239239

240-
sprintf(safe_process_name, "safe_process[%ld]", (long) own_pid);
240+
snprintf(safe_process_name, sizeof(safe_process_name),
241+
"safe_process[%ld]", (long) own_pid);
241242

242243
message("Started");
243244

plugin/type_inet/sql_type_inet.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ size_t Inet6::to_string(char *dst, size_t dstsize) const
500500
//
501501
// If it is not the last field, append closing ':'.
502502

503-
p += sprintf(p, "%x", ipv6_words[i]);
503+
p += snprintf(p, dstend - p, "%x", ipv6_words[i]);
504504

505505
if (i + 1 != IN6_ADDR_NUM_WORDS)
506506
{

sql/gcalc_slicescan.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ const char *gcalc_ev_name(int ev)
9898
}
9999

100100

101-
static int gcalc_pi_str(char *str, const Gcalc_heap::Info *pi, const char *postfix)
101+
static int gcalc_pi_str(char *str, size_t str_size, const Gcalc_heap::Info *pi, const char *postfix)
102102
{
103-
return sprintf(str, "%s %d %d | %s %d %d%s",
103+
return snprintf(str, str_size, "%s %d %d | %s %d %d%s",
104104
GCALC_SIGN(pi->node.shape.ix[0]) ? "-":"", FIRST_DIGIT(pi->node.shape.ix[0]),pi->node.shape.ix[1],
105105
GCALC_SIGN(pi->node.shape.iy[0]) ? "-":"", FIRST_DIGIT(pi->node.shape.iy[0]),pi->node.shape.iy[1],
106106
postfix);
@@ -130,7 +130,7 @@ static void GCALC_DBUG_PRINT_PI(const Gcalc_heap::Info *pi)
130130
#endif
131131
return;
132132
}
133-
n_buf= gcalc_pi_str(buf, pi, "");
133+
n_buf= gcalc_pi_str(buf, sizeof(buf), pi, "");
134134
buf[n_buf]= 0;
135135
GCALC_DBUG_PRINT(("%s", buf));
136136
}
@@ -146,14 +146,14 @@ static void GCALC_DBUG_PRINT_SLICE(const char *header,
146146
for (; slice; slice= slice->get_next())
147147
{
148148
size_t lnbuf= nbuf;
149-
lnbuf+= sprintf(buf + lnbuf, "%d\t", slice->thread);
150-
lnbuf+= sprintf(buf + lnbuf, "%s\t", gcalc_ev_name(slice->event));
149+
lnbuf+= snprintf(buf + lnbuf, sizeof(buf) - lnbuf, "%d\t", slice->thread);
150+
lnbuf+= snprintf(buf + lnbuf, sizeof(buf) - lnbuf, "%s\t", gcalc_ev_name(slice->event));
151151

152-
lnbuf+= gcalc_pi_str(buf + lnbuf, slice->pi, "\t");
152+
lnbuf+= gcalc_pi_str(buf + lnbuf, sizeof(buf) - (lnbuf), slice->pi, "\t");
153153
if (slice->is_bottom())
154-
lnbuf+= sprintf(buf+lnbuf, "bt\t");
154+
lnbuf+= snprintf(buf+lnbuf, sizeof(buf) - lnbuf, "bt\t");
155155
else
156-
lnbuf+= gcalc_pi_str(buf+lnbuf, slice->next_pi, "\t");
156+
lnbuf+= gcalc_pi_str(buf+lnbuf, sizeof(buf) - lnbuf, slice->next_pi, "\t");
157157
buf[lnbuf]= 0;
158158
GCALC_DBUG_PRINT(("%s", buf));
159159
}

sql/log.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,13 +2031,14 @@ binlog_commit_flush_stmt_cache(THD *thd, bool all,
20312031
}
20322032

20332033

2034-
inline size_t serialize_with_xid(XID *xid, char *buf,
2034+
inline size_t serialize_with_xid(XID *xid, char *buf, size_t buf_size,
20352035
const char *query, size_t q_len)
20362036
{
20372037
memcpy(buf, query, q_len);
20382038

20392039
return
2040-
q_len + strlen(static_cast<event_xid_t*>(xid)->serialize(buf + q_len));
2040+
q_len + strlen(static_cast<event_xid_t*>(xid)->serialize(buf + q_len,
2041+
buf_size - q_len));
20412042
}
20422043

20432044

@@ -2069,7 +2070,7 @@ binlog_commit_flush_trx_cache(THD *thd, bool all, binlog_cache_mngr *cache_mngr,
20692070
XA_PREPARED);
20702071

20712072
buflen= serialize_with_xid(thd->transaction->xid_state.get_xid(),
2072-
buf, query, q_len);
2073+
buf, sizeof(buf), query, q_len);
20732074
}
20742075
Query_log_event end_evt(thd, buf, buflen, TRUE, TRUE, TRUE, 0);
20752076

@@ -2100,7 +2101,7 @@ binlog_rollback_flush_trx_cache(THD *thd, bool all,
21002101
/* for not prepared use plain ROLLBACK */
21012102
if (thd->transaction->xid_state.get_state_code() == XA_PREPARED)
21022103
buflen= serialize_with_xid(thd->transaction->xid_state.get_xid(),
2103-
buf, query, q_len);
2104+
buf, sizeof(buf), query, q_len);
21042105
}
21052106
Query_log_event end_evt(thd, buf, buflen, TRUE, TRUE, TRUE, 0);
21062107

@@ -2332,7 +2333,8 @@ static int binlog_commit_flush_xa_prepare(THD *thd, bool all,
23322333

23332334
memcpy(buf, query, q_len);
23342335
buflen= q_len +
2335-
strlen(static_cast<event_xid_t*>(xid)->serialize(buf + q_len));
2336+
strlen(static_cast<event_xid_t*>(xid)->serialize(buf + q_len,
2337+
sizeof(buf) - q_len));
23362338
cache_data= cache_mngr->get_binlog_cache_data(true);
23372339
file= &cache_data->cache_log;
23382340
thd->lex->sql_command= SQLCOM_XA_END;

0 commit comments

Comments
 (0)