Skip to content

Commit 81f8b6f

Browse files
author
gkodinov
committed
MDEV-38499: cmake and compile errors on MacOSX when compiling
mariadb from a git tree Fix the warnings issued by a normal MacOSX compile. Problems: 1. sprintf is deprecated in favor of snprintf 2. bison incorrectly issues a warning when it sees "b4_bin" 3. MacOSX linker issues a warning about duplicate mysys/dbug/etc libraries. On 1: replaced the relevant sprintf with snprintf. On 2: worked around by adding a compiler define with a different name aliasing the character set variable used with a name that won't trigger the bison warning On 3: This is due to the fact that there's a circular dependecy between mysys and dbug (among others). Turned the warning off by suppressing the duplicate library warning.
1 parent 5ed3668 commit 81f8b6f

File tree

24 files changed

+150
-92
lines changed

24 files changed

+150
-92
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

@@ -7658,11 +7661,13 @@ int main(int argc, char **argv)
76587661

76597662
if (opt_master_data && do_show_master_status(mysql, consistent_binlog_pos,
76607663
have_mariadb_gtid,
7661-
opt_use_gtid, master_set_gtid_pos))
7664+
opt_use_gtid, master_set_gtid_pos,
7665+
sizeof(master_set_gtid_pos)))
76627666
goto err;
76637667
if (opt_slave_data && do_show_slave_status(mysql,
76647668
have_mariadb_gtid,
7665-
opt_use_gtid, slave_set_gtid_pos))
7669+
opt_use_gtid, slave_set_gtid_pos,
7670+
sizeof(slave_set_gtid_pos)))
76667671
goto err;
76677672
if (opt_single_transaction && do_unlock_tables(mysql)) /* unlock but no commit! */
76687673
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

mysys/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,19 @@ IF (WIN32)
189189
TARGET_LINK_LIBRARIES(mysys iphlpapi dbghelp ws2_32 synchronization)
190190
ENDIF(WIN32)
191191

192+
# This is a workaround for the warning about duplicate libraries on macOS.
193+
# The issue is as follows: mysys depends on dbug and dbug depends on mysys.
194+
# This causes cmake to append dbug twice when you append mysys as a library.
195+
# And you get a warning from the MacOSX linker.
196+
# TODO: to remove the circular dependency and this workaround.
197+
include(CheckLinkerFlag)
198+
IF(APPLE AND (CMAKE_VERSION VERSION_GREATER_EQUAL "3.18"))
199+
CHECK_LINKER_FLAG(C "LINKER:-no_warn_duplicate_libraries" HAVE_NO_WARN_DUPLICATE_LIBRARIES)
200+
IF(HAVE_NO_WARN_DUPLICATE_LIBRARIES)
201+
TARGET_LINK_OPTIONS(mysys INTERFACE LINKER:-no_warn_duplicate_libraries)
202+
ENDIF()
203+
ENDIF()
204+
192205
# Need explicit pthread for gcc -fsanitize=address
193206
IF(CMAKE_USE_PTHREADS_INIT AND CMAKE_C_FLAGS MATCHES "-fsanitize=")
194207
TARGET_LINK_LIBRARIES(mysys pthread)

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
}

0 commit comments

Comments
 (0)