Skip to content

Commit

Permalink
(Re)ënable ATTRIBUTE_FORMAT in DBUG_PRINT
Browse files Browse the repository at this point in the history
Reënable `_db_doprnt_` (better known by its frontend `DBUG_PRINT`)’s
`ATTRIBUTE_FORMAT` to leverage GCC `-Wformat` checking.
Per MDEV-21978 discussion on Zulip, `WAITING_FOR_BUGFIX_TO_VSPRINTF` introduced
in c4bf4b7 will be no more, but the preference for `%b`
(now migrated to `%sB`) was intended.

Most of the mistakes fixed in this commit were passing `size_t` arguments
without using the C/C++-standard `%zu` construct.
  • Loading branch information
ParadoxV5 committed Aug 5, 2024
1 parent 8cc689c commit 4544a03
Show file tree
Hide file tree
Showing 15 changed files with 22 additions and 26 deletions.
3 changes: 2 additions & 1 deletion dbug/dbug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 1 addition & 5 deletions include/my_dbug.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion mysys/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions mysys/waiting_threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -1142,4 +1142,3 @@ void wt_thd_release(WT_THD *thd, const WT_RESOURCE_ID *resid)
reset_dynamic(&thd->my_resources);
DBUG_VOID_RETURN;
}

4 changes: 2 additions & 2 deletions sql/ha_partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion sql/log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions sql/log_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion sql/opt_range.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion sql/partition_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions sql/protocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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--);
}
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/fsp/fsp0fsp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions storage/maria/ma_loghandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 -
Expand Down Expand Up @@ -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 ==
Expand Down

0 comments on commit 4544a03

Please sign in to comment.