From dd6d9ea702ed06f763abdd0927582e34a6b50290 Mon Sep 17 00:00:00 2001 From: ParadoxV5 Date: Mon, 5 Aug 2024 14:39:09 -0600 Subject: [PATCH] =?UTF-8?q?Re=C3=ABnable=20ATTRIBUTE=5FFORMAT=20on=20DBUG?= =?UTF-8?q?=5FPRINT=20&=20t/eprint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (Re)ënable the `ATTRIBUTE_FORMAT` on `my_dbug.h`’s `_db_doprnt_` (better known by its frontend `DBUG_PRINT`) and `ma_recovery_util.h`’s `tprint` & `eprint` to leverage GCC `-Wformat` checking. c4bf4b7aef introduced `WAITING_FOR_BUGFIX_TO_VSPRINTF` to conditionally (read: temporarily) disable `ATTRIBUTE_FORMAT`. Whatever that bug was aside, MDEV-21978 Zulip suggested that the preference for `%b` was probably intended, although c52e62a76f reverted the one in `storage/maria/ma_recovery.c` back to `%s`. All mistake fixes and extension migrations (e.g., `%b` ➡ `%sB`) included in this commit were on `DBUG_PRINT` – no `t`/`eprint` problems were caught. Most of these mistakes were passing `size_t` arguments without using the C/C++-standard `%zu` construct. --- dbug/dbug.c | 3 ++- include/my_dbug.h | 6 +----- mysys/array.c | 2 +- mysys/waiting_threads.c | 3 +-- sql/ha_partition.cc | 4 ++-- sql/log.cc | 2 +- sql/log_event.cc | 4 ++-- sql/mysqld.cc | 2 +- sql/opt_range.cc | 2 +- sql/partition_info.cc | 2 +- sql/protocol.cc | 4 ++-- sql/sql_plugin.cc | 2 +- storage/innobase/fsp/fsp0fsp.cc | 2 +- storage/innobase/handler/ha_innodb.cc | 2 +- storage/maria/ma_loghandler.c | 8 ++++---- storage/maria/ma_recovery_util.h | 5 ----- 16 files changed, 22 insertions(+), 31 deletions(-) diff --git a/dbug/dbug.c b/dbug/dbug.c index ac645c6445408..857de55b7135f 100644 --- a/dbug/dbug.c +++ b/dbug/dbug.c @@ -298,7 +298,8 @@ static void Indent(CODE_STATE *cs, int indent); static void DbugFlush(CODE_STATE *); static void DbugExit(const char *why); static const char *DbugStrTok(const char *s); -static void DbugVfprintf(FILE *stream, const char* format, va_list args); +static void DbugVfprintf(FILE *stream, const char* format, va_list args) + ATTRIBUTE_FORMAT(printf, 2, 0); /* * Miscellaneous printf format strings. diff --git a/include/my_dbug.h b/include/my_dbug.h index 02caadbff4817..0c0dabef64e18 100644 --- a/include/my_dbug.h +++ b/include/my_dbug.h @@ -51,11 +51,7 @@ extern void _db_enter_(const char *_func_, const char *_file_, uint _line_, struct _db_stack_frame_ *_stack_frame_); extern void _db_return_(struct _db_stack_frame_ *_stack_frame_); extern int _db_pargs_(uint _line_,const char *keyword); -extern void _db_doprnt_(const char *format,...) -#ifdef WAITING_FOR_BUGFIX_TO_VSPRINTF - ATTRIBUTE_FORMAT(printf, 1, 2) -#endif - ; +extern void _db_doprnt_(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2); extern void _db_dump_(uint _line_,const char *keyword, const unsigned char *memory, size_t length); extern void _db_end_(void); diff --git a/mysys/array.c b/mysys/array.c index 02a54d4465682..b44d34285fcbd 100644 --- a/mysys/array.c +++ b/mysys/array.c @@ -318,7 +318,7 @@ void get_dynamic(DYNAMIC_ARRAY *array, void *element, size_t idx) { if (unlikely(idx >= array->elements)) { - DBUG_PRINT("warning",("To big array idx: %d, array size is %d", + DBUG_PRINT("warning",("To big array idx: %zu, array size is %zu", idx,array->elements)); bzero(element,array->size_of_element); return; diff --git a/mysys/waiting_threads.c b/mysys/waiting_threads.c index 7c20c2eec5df0..f5bed7671b068 100644 --- a/mysys/waiting_threads.c +++ b/mysys/waiting_threads.c @@ -829,7 +829,7 @@ static int unlock_lock_and_free_resource(WT_THD *thd, WT_RESOURCE *rc) if (rc->owners.elements || rc->waiter_count) { - DBUG_PRINT("wt", ("nothing to do, %u owners, %u waiters", + DBUG_PRINT("wt", ("nothing to do, %zu owners, %u waiters", rc->owners.elements, rc->waiter_count)); rc_unlock(rc); DBUG_RETURN(0); @@ -1142,4 +1142,3 @@ void wt_thd_release(WT_THD *thd, const WT_RESOURCE_ID *resid) reset_dynamic(&thd->my_resources); DBUG_VOID_RETURN; } - diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 32344ea0071a2..91dabbacd5b9e 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -1499,8 +1499,8 @@ bool print_admin_msg(THD* thd, uint len, Also we likely need to lock mutex here (in both cases with protocol and push_warning). */ - DBUG_PRINT("info",("print_admin_msg: %s, %s, %s, %s", name, op_name, - msg_type, msgbuf)); + DBUG_PRINT("info",("print_admin_msg: %s, %s, %s, %s", name, op_name->str, + msg_type->str, msgbuf)); protocol->prepare_for_resend(); protocol->store(name, length, system_charset_info); protocol->store(op_name, system_charset_info); diff --git a/sql/log.cc b/sql/log.cc index 6dd0be652db35..618935b077b7c 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -12121,7 +12121,7 @@ int TC_LOG_BINLOG::recover(LOG_INFO *linfo, const char *last_log_name, Query_log_event *query_ev= (Query_log_event*) ev; if (query_ev->xid) { - DBUG_PRINT("QQ", ("xid: %llu xid")); + DBUG_PRINT("QQ", ("xid: %llu xid", query_ev->xid)); DBUG_ASSERT(sizeof(query_ev->xid) == sizeof(my_xid)); uchar *x= (uchar *) memdup_root(&mem_root, (uchar*) &query_ev->xid, diff --git a/sql/log_event.cc b/sql/log_event.cc index 250e814283890..049006da622e3 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -3149,7 +3149,7 @@ Rows_log_event::Rows_log_event(const uchar *buf, uint event_len, uchar *ptr_after_width= (uchar*) ptr_width; DBUG_PRINT("debug", ("Reading from %p", ptr_after_width)); m_width= net_field_length(&ptr_after_width); - DBUG_PRINT("debug", ("m_width=%lu", m_width)); + DBUG_PRINT("debug", ("m_width=%u", m_width)); /* Avoid reading out of buffer */ if (ptr_after_width + (m_width + 7) / 8 > (uchar*)buf + event_len) @@ -3212,7 +3212,7 @@ Rows_log_event::Rows_log_event(const uchar *buf, uint event_len, DBUG_VOID_RETURN; } size_t const data_size= event_len - read_size; - DBUG_PRINT("info",("m_table_id: %llu m_flags: %d m_width: %lu data_size: %lu", + DBUG_PRINT("info",("m_table_id: %llu m_flags: %d m_width: %u data_size: %lu", m_table_id, m_flags, m_width, (ulong) data_size)); m_rows_buf= (uchar*) my_malloc(PSI_INSTRUMENT_ME, data_size, MYF(MY_WME)); diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 6d3a14ad866f5..096999cfb4ed7 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -5721,7 +5721,7 @@ static void test_lc_time_sz() (*loc)->max_day_name_length != max_day_len) { DBUG_PRINT("Wrong max day name(or month name) length for locale:", - ("%s", (*loc)->name)); + ("%s", (*loc)->name.str)); DBUG_ASSERT(0); } } diff --git a/sql/opt_range.cc b/sql/opt_range.cc index a32c0f67e1cc5..fc6023573f0cd 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -3106,7 +3106,7 @@ SQL_SELECT::test_quick_select(THD *thd, group_by_optimization_used= 1; param.table->set_opt_range_condition_rows(group_trp->records); DBUG_PRINT("info", ("table_rows: %llu opt_range_condition_rows: %llu " - "group_trp->records: %ull", + "group_trp->records: %llu", table_records, param.table->opt_range_condition_rows, group_trp->records)); diff --git a/sql/partition_info.cc b/sql/partition_info.cc index 6390dfab3b4fc..6802e99c2401a 100644 --- a/sql/partition_info.cc +++ b/sql/partition_info.cc @@ -179,7 +179,7 @@ bool partition_info::add_named_partition(const char *part_name, size_t length) } DBUG_PRINT("info", ("Found partition %u is_subpart %d for name %.*s", part_def->part_id, part_def->is_subpart, - length, part_name)); + (int) length, part_name)); DBUG_RETURN(false); } diff --git a/sql/protocol.cc b/sql/protocol.cc index ca7803248c63b..3a1e42cbe889d 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -1491,7 +1491,7 @@ bool Protocol_text::store_str(const char *from, size_t length, CHARSET_INFO *fromcs, CHARSET_INFO *tocs) { #ifndef DBUG_OFF - DBUG_PRINT("info", ("Protocol_text::store field %u : %.*b", field_pos, + DBUG_PRINT("info", ("Protocol_text::store field %u : %.*sB", field_pos, (int) length, (length == 0 ? "" : from))); DBUG_ASSERT(field_handlers == 0 || field_pos < field_count); DBUG_ASSERT(valid_handler(field_pos, PROTOCOL_SEND_STRING)); @@ -1507,7 +1507,7 @@ bool Protocol_text::store_numeric_zerofill_str(const char *from, { #ifndef DBUG_OFF DBUG_PRINT("info", - ("Protocol_text::store_numeric_zerofill_str field %u : %.*b", + ("Protocol_text::store_numeric_zerofill_str field %u : %.*sB", field_pos, (int) length, (length == 0 ? "" : from))); DBUG_ASSERT(field_handlers == 0 || field_pos < field_count); DBUG_ASSERT(valid_handler(field_pos, send_type)); diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 5ce7dc57b2380..49d27e6d2ea8a 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -3390,7 +3390,7 @@ void plugin_thdvar_cleanup(THD *thd) if ((idx= thd->lex->plugins.elements)) { list= ((plugin_ref*) thd->lex->plugins.buffer) + idx - 1; - DBUG_PRINT("info",("unlocking %d plugins", idx)); + DBUG_PRINT("info",("unlocking %zu plugins", idx)); while ((uchar*) list >= thd->lex->plugins.buffer) intern_plugin_unlock(NULL, *list--); } diff --git a/storage/innobase/fsp/fsp0fsp.cc b/storage/innobase/fsp/fsp0fsp.cc index af5fd1305fcff..87882eee0ecee 100644 --- a/storage/innobase/fsp/fsp0fsp.cc +++ b/storage/innobase/fsp/fsp0fsp.cc @@ -2643,7 +2643,7 @@ dberr_t fseg_free_page(fseg_header_t *seg_header, fil_space_t *space, mtr->x_lock_space(space); DBUG_PRINT("fseg_free_page", - ("space_id: " ULINTPF ", page_no: %u", space->id, offset)); + ("space_id: %" PRIu32 ", page_no: %" PRIu32, space->id, offset)); dberr_t err; if (fseg_inode_t *seg_inode= fseg_inode_try_get(seg_header, diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 36b331f19f7cb..b7bc093feb151 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -1969,7 +1969,7 @@ static int innodb_check_version(handlerton *hton, const char *path, const trx_id_t trx_id= table->def_trx_id; DBUG_ASSERT(trx_id <= create_id); dict_table_close(table); - DBUG_PRINT("info", ("create_id: %llu trx_id: %llu", create_id, trx_id)); + DBUG_PRINT("info", ("create_id: %llu trx_id: %" PRIu64, create_id, trx_id)); DBUG_RETURN(create_id != trx_id); } else diff --git a/storage/maria/ma_loghandler.c b/storage/maria/ma_loghandler.c index 7d871a2e68a42..687cff860a1ce 100644 --- a/storage/maria/ma_loghandler.c +++ b/storage/maria/ma_loghandler.c @@ -5734,7 +5734,7 @@ translog_write_variable_record_mgroup(LSN *lsn, goto err_unlock; } - DBUG_PRINT("info", ("chunk: #%u first_page: %u (%u) " + DBUG_PRINT("info", ("chunk: #%zu first_page: %u (%u) " "full_pages: %lu (%lu) " "Left %lu", groups.elements, @@ -5902,8 +5902,8 @@ translog_write_variable_record_mgroup(LSN *lsn, record_rest + header_fixed_part + (groups.elements - groups_per_page * (chunk0_pages - 1)) * (7 + 1)) chunk0_pages++; - DBUG_PRINT("info", ("chunk0_pages: %u groups %u groups per full page: %u " - "Group on last page: %u", + DBUG_PRINT("info", ("chunk0_pages: %u groups %zu groups per full page: %u " + "Group on last page: %zu", chunk0_pages, groups.elements, groups_per_page, (groups.elements - @@ -8731,7 +8731,7 @@ my_bool translog_purge(TRANSLOG_ADDRESS low) log_descriptor.open_files.elements); DBUG_ASSERT(log_descriptor.min_file == i); file= *((TRANSLOG_FILE **)pop_dynamic(&log_descriptor.open_files)); - DBUG_PRINT("info", ("Files : %d", log_descriptor.open_files.elements)); + DBUG_PRINT("info", ("Files : %zu", log_descriptor.open_files.elements)); DBUG_ASSERT(i == file->number); log_descriptor.min_file++; DBUG_ASSERT(log_descriptor.max_file - log_descriptor.min_file + 1 == diff --git a/storage/maria/ma_recovery_util.h b/storage/maria/ma_recovery_util.h index 39c16bc5dffdb..0b02f8e51cb1b 100644 --- a/storage/maria/ma_recovery_util.h +++ b/storage/maria/ma_recovery_util.h @@ -31,12 +31,7 @@ extern FILE *tracef; my_bool _ma_redo_not_needed_for_page(uint16 shortid, LSN lsn, pgcache_page_no_t page, my_bool index); -#ifdef WAITING_FOR_BUGFIX_TO_VSPRINTF void tprint(FILE *trace_file, const char *format, ...) ATTRIBUTE_FORMAT(printf, 2, 3); void eprint(FILE *trace_file, const char *format, ...) ATTRIBUTE_FORMAT(printf, 2, 3); -#else -void tprint(FILE *trace_file, const char *format, ...); -void eprint(FILE *trace_file, const char *format, ...); -#endif