diff --git a/client/mysql_upgrade.c b/client/mysql_upgrade.c index 3f60d169edcce..b44305022d616 100644 --- a/client/mysql_upgrade.c +++ b/client/mysql_upgrade.c @@ -556,7 +556,7 @@ static void find_tool(char *tool_executable_name, const char *tool_name, len= (int)(last_fn_libchar - self_name); - my_snprintf(tool_executable_name, FN_REFLEN, "%.*b%c%s", + my_snprintf(tool_executable_name, FN_REFLEN, "%.*sB%c%s", len, self_name, FN_LIBCHAR, tool_name); } diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c index b28bcd407d60f..51e99607fa2e3 100644 --- a/client/mysqlcheck.c +++ b/client/mysqlcheck.c @@ -548,7 +548,7 @@ static int is_view(const char *table) int view; DBUG_ENTER("is_view"); - my_snprintf(query, sizeof(query), "SHOW CREATE TABLE %`s", table); + my_snprintf(query, sizeof(query), "SHOW CREATE TABLE %sQ", table); if (mysql_query(sock, query)) { fprintf(stderr, "Failed to %s\n", query); @@ -797,7 +797,7 @@ static int fix_table_storage_name(const char *name) if (strncmp(name, "#mysql50#", 9)) DBUG_RETURN(1); - my_snprintf(qbuf, sizeof(qbuf), "RENAME TABLE %`s TO %`s", + my_snprintf(qbuf, sizeof(qbuf), "RENAME TABLE %sQ TO %sQ", name, name + 9); rc= run_query(qbuf, 1); @@ -814,7 +814,7 @@ static int fix_database_storage_name(const char *name) if (strncmp(name, "#mysql50#", 9)) DBUG_RETURN(1); - my_snprintf(qbuf, sizeof(qbuf), "ALTER DATABASE %`s UPGRADE DATA DIRECTORY " + my_snprintf(qbuf, sizeof(qbuf), "ALTER DATABASE %sQ UPGRADE DATA DIRECTORY " "NAME", name); rc= run_query(qbuf, 1); if (!opt_silent) @@ -1023,7 +1023,7 @@ static void insert_table_name(DYNAMIC_ARRAY *arr, char *in, size_t dblen) { char buf[NAME_LEN*2+2]; in[dblen]= 0; - my_snprintf(buf, sizeof(buf), "%`s.%`s", in, in + dblen + 1); + my_snprintf(buf, sizeof(buf), "%sQ.%sQ", in, in + dblen + 1); insert_dynamic(arr, (uchar*) buf); } diff --git a/include/mysql/service_my_snprintf.h b/include/mysql/service_my_snprintf.h index d52302c9dac96..43c67e6dfc7e2 100644 --- a/include/mysql/service_my_snprintf.h +++ b/include/mysql/service_my_snprintf.h @@ -94,8 +94,10 @@ extern "C" { #endif extern struct my_snprintf_service_st { - size_t (*my_snprintf_type)(char*, size_t, const char*, ...); - size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list); + size_t (*my_snprintf_type)(char*, size_t, const char*, ...) + __attribute__((format(printf, 3, 4))); + size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list) + __attribute__((format(printf, 3, 0))); } *my_snprintf_service; #ifdef MYSQL_DYNAMIC_PLUGIN @@ -105,8 +107,10 @@ extern struct my_snprintf_service_st { #else -size_t my_snprintf(char* to, size_t n, const char* fmt, ...); -size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap); +size_t my_snprintf(char* to, size_t n, const char* fmt, ...) + __attribute__((format(printf, 3, 4))); +size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap) + __attribute__((format(printf, 3, 0))); #endif diff --git a/plugin/server_audit/server_audit.c b/plugin/server_audit/server_audit.c index d830169809f6b..ee33560ebf465 100644 --- a/plugin/server_audit/server_audit.c +++ b/plugin/server_audit/server_audit.c @@ -1415,7 +1415,7 @@ static size_t log_header(char *message, size_t message_len, if (output_type == OUTPUT_SYSLOG) return my_snprintf(message, message_len, "%.*s,%.*s,%.*s,%d,%lld,%s", - (unsigned int) serverhost_len, serverhost, + (int) serverhost_len, serverhost, username_len, username, host_len, host, connection_id, query_id, operation); @@ -1425,7 +1425,7 @@ static size_t log_header(char *message, size_t message_len, "%04d%02d%02d %02d:%02d:%02d,%.*s,%.*s,%.*s,%d,%lld,%s", tm_time.tm_year+1900, tm_time.tm_mon+1, tm_time.tm_mday, tm_time.tm_hour, tm_time.tm_min, tm_time.tm_sec, - serverhost_len, serverhost, + (int) serverhost_len, serverhost, username_len, username, host_len, host, connection_id, query_id, operation); @@ -1494,7 +1494,7 @@ static int log_connection_event(const struct mysql_event_connection *event, event->ip, event->ip_length, event->thread_id, 0, type); csize+= my_snprintf(message+csize, sizeof(message) - 1 - csize, - ",%.*s,,%d", event->database.length, event->database.str, event->status); + ",%.*s,,%d", (int) event->database.length, event->database.str, event->status); message[csize]= '\n'; return write_log(message, csize + 1, 1); } @@ -1926,9 +1926,9 @@ static int log_table(const struct connection_info *cn, event->host, SAFE_STRLEN_UI(event->host), event->ip, SAFE_STRLEN_UI(event->ip), event->thread_id, cn->query_id, type); - csize+= my_snprintf(message+csize, sizeof(message) - 1 - csize, - ",%.*s,%.*s,",event->database.length, event->database.str, - event->table.length, event->table.str); + csize+= my_snprintf(message+csize, sizeof(message) - 1 - csize, ",%.*s,%.*s,", + (int) event->database.length, event->database.str, + (int) event->table.length, event->table.str); message[csize]= '\n'; return write_log(message, csize + 1, 1); } @@ -1949,10 +1949,11 @@ static int log_rename(const struct connection_info *cn, event->ip, SAFE_STRLEN_UI(event->ip), event->thread_id, cn->query_id, "RENAME"); csize+= my_snprintf(message+csize, sizeof(message) - 1 - csize, - ",%.*s,%.*s|%.*s.%.*s,",event->database.length, event->database.str, - event->table.length, event->table.str, - event->new_database.length, event->new_database.str, - event->new_table.length, event->new_table.str); + ",%.*s,%.*s|%.*s.%.*s,", + (int) event->database.length, event->database.str, + (int) event->table.length, event->table.str, + (int) event->new_database.length, event->new_database.str, + (int) event->new_table.length, event->new_table.str); message[csize]= '\n'; return write_log(message, csize + 1, 1); } @@ -3127,4 +3128,3 @@ void __attribute__ ((constructor)) audit_plugin_so_init(void) return; #endif } - diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 880634fca87ea..5e43b327a3db8 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -6212,8 +6212,8 @@ bool Regexp_processor_pcre::compile(String *pattern, bool send_error) int lmsg= pcre2_get_error_message(pcreErrorNumber, (PCRE2_UCHAR8 *)buff, sizeof(buff)); if (lmsg >= 0) - my_snprintf(buff+lmsg, sizeof(buff)-lmsg, - " at offset %d", pcreErrorOffset); + snprintf(buff+lmsg, sizeof(buff)-lmsg, + " at offset %zu", pcreErrorOffset); my_error(ER_REGEXP_ERROR, MYF(0), buff); } return true; @@ -8013,4 +8013,3 @@ Item *Item_equal::multiple_equality_transformer(THD *thd, uchar *arg) break; } } - diff --git a/sql/log_event_client.cc b/sql/log_event_client.cc index d6a8dddfc8037..7f6b031fa4b6b 100644 --- a/sql/log_event_client.cc +++ b/sql/log_event_client.cc @@ -3284,7 +3284,7 @@ static void get_type_name(uint type, unsigned char** meta_ptr, { switch (type) { case MYSQL_TYPE_LONG: - my_snprintf(typestr, typestr_length, "%s", "INT"); + my_snprintf(typestr, typestr_length, "INT"); break; case MYSQL_TYPE_TINY: my_snprintf(typestr, typestr_length, "TINYINT"); @@ -3354,20 +3354,21 @@ static void get_type_name(uint type, unsigned char** meta_ptr, break; case MYSQL_TYPE_BLOB: { - bool is_text= (cs && cs->number != my_charset_bin.number); - const char *names[5][2] = { - {"INVALID_BLOB(%d)", "INVALID_TEXT(%d)"}, - {"TINYBLOB", "TINYTEXT"}, - {"BLOB", "TEXT"}, - {"MEDIUMBLOB", "MEDIUMTEXT"}, - {"LONGBLOB", "LONGTEXT"} + const char *type_name= + (cs && cs->number != my_charset_bin.number) ? "TEXT" : "BLOB"; + const char *names[5]= { + NullS, + "TINY", + "", + "MEDIUM", + "LONG" }; unsigned char size= **meta_ptr; if (size == 0 || size > 4) - my_snprintf(typestr, typestr_length, names[0][is_text], size); + my_snprintf(typestr, typestr_length, "INVALID_%s(%d)", type_name, size); else - my_snprintf(typestr, typestr_length, names[**meta_ptr][is_text]); + my_snprintf(typestr, typestr_length, "%s%s", names[size], type_name); (*meta_ptr)++; } @@ -3404,7 +3405,7 @@ static void get_type_name(uint type, unsigned char** meta_ptr, "MULTILINESTRING", "MULTIPOLYGON", "GEOMETRYCOLLECTION" }; if (geometry_type < 8) - my_snprintf(typestr, typestr_length, names[geometry_type]); + my_snprintf(typestr, typestr_length, "%s", names[geometry_type]); else my_snprintf(typestr, typestr_length, "INVALID_GEOMETRY_TYPE(%u)", geometry_type); diff --git a/sql/sql_admin.cc b/sql/sql_admin.cc index 835d910282d1d..eb457ce60dc53 100644 --- a/sql/sql_admin.cc +++ b/sql/sql_admin.cc @@ -711,7 +711,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, protocol->store(&table_name, system_charset_info); protocol->store(operator_name, system_charset_info); protocol->store(&error_clex_str, system_charset_info); - length= my_snprintf(buff, sizeof(buff), + length= my_snprintf(buff, sizeof(buff), "%s", ER_THD(thd, ER_PARTITION_DOES_NOT_EXIST)); protocol->store(buff, length, system_charset_info); if(protocol->write()) diff --git a/sql/sql_db.cc b/sql/sql_db.cc index f9750ca6d8c16..9a238fdc3ee4d 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -1237,7 +1237,7 @@ mysql_rm_db_internal(THD *thd, const Lex_ident_db &db, bool if_exists, if (ha_table_exists(thd, &tbl->db, &tbl->table_name)) continue; - tbl_name_len= my_snprintf(quoted_name, sizeof(quoted_name), "%`s", + tbl_name_len= my_snprintf(quoted_name, sizeof(quoted_name), "%sQ", tbl->table_name.str); tbl_name_len++; /* +1 for the comma */ if (query_pos + tbl_name_len + 1 >= query_end) diff --git a/sql/sql_type.h b/sql/sql_type.h index 399362a316ef3..0d847e4bf5e0a 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -722,7 +722,7 @@ class Sec6 size_t to_string(char *to, size_t nbytes) const { return m_usec ? - my_snprintf(to, nbytes, "%s%llu.%06lu", + my_snprintf(to, nbytes, "%s%llu.%06u", m_neg ? "-" : "", m_sec, (uint) m_usec) : my_snprintf(to, nbytes, "%s%llu", m_neg ? "-" : "", m_sec); } diff --git a/sql/table.cc b/sql/table.cc index 913efd898b07c..675f331a1b0c8 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -4078,27 +4078,29 @@ static void print_long_unique_table(TABLE *table) " fields->offset,field->null_bit, field->null_pos and key_info ... \n" "\nPrinting Table keyinfo\n"); str.append(buff, strlen(buff)); - my_snprintf(buff, sizeof(buff), "\ntable->s->reclength %d\n" - "table->s->fields %d\n", + my_snprintf(buff, sizeof(buff), "\ntable->s->reclength %lu\n" + "table->s->fields %u\n", table->s->reclength, table->s->fields); str.append(buff, strlen(buff)); for (uint i= 0; i < table->s->keys; i++) { key_info_table= table->key_info + i; key_info_share= table->s->key_info + i; - my_snprintf(buff, sizeof(buff), "\ntable->key_info[%d] user_defined_key_parts = %d\n" - "table->key_info[%d] algorithm == HA_KEY_ALG_LONG_HASH = %d\n" - "table->key_info[%d] flags & HA_NOSAME = %d\n", - i, key_info_table->user_defined_key_parts, - i, key_info_table->algorithm == HA_KEY_ALG_LONG_HASH, - i, key_info_table->flags & HA_NOSAME); + my_snprintf(buff, sizeof(buff), + "\ntable->key_info[%d] user_defined_key_parts = %d\n" + "table->key_info[%d] algorithm == HA_KEY_ALG_LONG_HASH = %d\n" + "table->key_info[%d] flags & HA_NOSAME = %lu\n", + i, key_info_table->user_defined_key_parts, + i, key_info_table->algorithm == HA_KEY_ALG_LONG_HASH, + i, key_info_table->flags & HA_NOSAME); str.append(buff, strlen(buff)); - my_snprintf(buff, sizeof(buff), "\ntable->s->key_info[%d] user_defined_key_parts = %d\n" - "table->s->key_info[%d] algorithm == HA_KEY_ALG_LONG_HASH = %d\n" - "table->s->key_info[%d] flags & HA_NOSAME = %d\n", - i, key_info_share->user_defined_key_parts, - i, key_info_share->algorithm == HA_KEY_ALG_LONG_HASH, - i, key_info_share->flags & HA_NOSAME); + my_snprintf(buff, sizeof(buff), + "\ntable->s->key_info[%d] user_defined_key_parts = %d\n" + "table->s->key_info[%d] algorithm == HA_KEY_ALG_LONG_HASH = %d\n" + "table->s->key_info[%d] flags & HA_NOSAME = %lu\n", + i, key_info_share->user_defined_key_parts, + i, key_info_share->algorithm == HA_KEY_ALG_LONG_HASH, + i, key_info_share->flags & HA_NOSAME); str.append(buff, strlen(buff)); key_part = key_info_table->key_part; my_snprintf(buff, sizeof(buff), "\nPrinting table->key_info[%d].key_part[0] info\n" @@ -4131,9 +4133,9 @@ static void print_long_unique_table(TABLE *table) { field= table->field[i]; my_snprintf(buff, sizeof(buff), "\ntable->field[%d]->field_name %s\n" - "table->field[%d]->offset = %d\n" + "table->field[%d]->offset = %ld\n" "table->field[%d]->field_length = %d\n" - "table->field[%d]->null_pos wrt to record 0 = %d\n" + "table->field[%d]->null_pos wrt to record 0 = %ld\n" "table->field[%d]->null_bit_pos = %d\n", i, field->field_name.str, i, field->ptr- table->record[0], diff --git a/sql/wsrep_var.cc b/sql/wsrep_var.cc index c55d713ed18c6..f9b795babe980 100644 --- a/sql/wsrep_var.cc +++ b/sql/wsrep_var.cc @@ -966,7 +966,7 @@ bool wsrep_max_ws_size_update(sys_var *self, THD *thd, enum_var_type) { char max_ws_size_opt[128]; my_snprintf(max_ws_size_opt, sizeof(max_ws_size_opt), - "repl.max_ws_size=%d", wsrep_max_ws_size); + "repl.max_ws_size=%lu", wsrep_max_ws_size); enum wsrep::provider::status ret= Wsrep_server_state::instance().provider().options(max_ws_size_opt); if (ret) { @@ -1120,4 +1120,3 @@ bool wsrep_gtid_domain_id_update(sys_var* self, THD *thd, enum_var_type) wsrep_gtid_server.domain_id= wsrep_gtid_domain_id; return false; } - diff --git a/storage/example/ha_example.cc b/storage/example/ha_example.cc index adcce268214dd..08a26ffa5b1dd 100644 --- a/storage/example/ha_example.cc +++ b/storage/example/ha_example.cc @@ -1078,7 +1078,7 @@ static int show_func_example(MYSQL_THD thd, struct st_mysql_show_var *var, var->value= buf; // it's of SHOW_VAR_FUNC_BUFF_SIZE bytes my_snprintf(buf, SHOW_VAR_FUNC_BUFF_SIZE, "enum_var is %lu, ulong_var is %lu, int_var is %d, " - "double_var is %f, %.6b", // %b is a MariaDB/MySQL extension + "double_var is %f, %.6sB", // %sB is a MariaDB extension srv_enum_var, srv_ulong_var, THDVAR(thd, int_var), srv_double_var, "really"); return 0;