Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDEV-35599: Replace (u)llstr() with %llu/d #3724

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion client/mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5188,7 +5188,7 @@ static int com_status(String *, char *)
tee_fprintf(stdout, "Protocol version:\t%d\n", mysql_get_proto_info(&mysql));
tee_fprintf(stdout, "Connection:\t\t%s\n", mysql_get_host_info(&mysql));
if ((id= mysql_insert_id(&mysql)))
tee_fprintf(stdout, "Insert id:\t\t%s\n", llstr(id, buff));
tee_fprintf(stdout, "Insert id:\t\t%lld\n", id);

/* "limit 1" is protection against SQL_SELECT_LIMIT=0 */
if (mysql_real_query_for_lazy(C_STRING_WITH_LEN(
Expand Down
13 changes: 5 additions & 8 deletions client/mysqladmin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -850,15 +850,14 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
for (;;)
{
/* We don't use mysql_kill(), since it only handles 32-bit IDs. */
char buff[26], *out; /* "KILL " + max 20 digs + NUL */
out= strxmov(buff, "KILL ", NullS);
ullstr(strtoull(pos, NULL, 0), out);
snprintf(buff, sizeof(buff), "KILL %llu",
// extract `ulonglong` number with strtoull() (note: it returns `ulong` on Linux!)
(unsigned long long) strtoull(pos, NULL, 0));

if (mysql_query(mysql, buff))
{
/* out still points to just the number */
my_printf_error(0, "kill failed on %s; error: '%s'", error_flags,
out, mysql_error(mysql));
&buff[5], mysql_error(mysql));
error=1;
}
if (!(pos=strchr(pos,',')))
Expand Down Expand Up @@ -1473,7 +1472,6 @@ static void print_row(MYSQL_RES *result, MYSQL_ROW cur,
static void print_relative_row(MYSQL_RES *result, MYSQL_ROW cur, uint row)
{
ulonglong tmp;
char buff[22];
MYSQL_FIELD *field;

mysql_field_seek(result, 0);
Expand All @@ -1482,8 +1480,7 @@ static void print_relative_row(MYSQL_RES *result, MYSQL_ROW cur, uint row)

field = mysql_fetch_field(result);
tmp = cur[1] ? strtoull(cur[1], NULL, 10) : (ulonglong) 0;
printf(" %-*s|\n", (int) field->max_length + 1,
llstr((tmp - last_values[row]), buff));
printf(" %-*lld|\n", (int) field->max_length + 1, tmp - last_values[row]);
last_values[row] = tmp;
}

Expand Down
13 changes: 4 additions & 9 deletions client/mysqlbinlog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,6 @@ static bool print_row_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev,
Table_map_log_event *ignored_map=
print_event_info->m_table_map_ignored.get_table(table_id);
bool skip_event= (ignored_map != NULL);
char ll_buff[21];
bool result= 0;

if (opt_flashback)
Expand Down Expand Up @@ -821,8 +820,7 @@ static bool print_row_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev,
if (is_stmt_end && !result)
{
if (print_event_info->print_row_count)
fprintf(result_file, "# Number of rows: %s\n",
llstr(print_event_info->row_events, ll_buff));
fprintf(result_file, "# Number of rows: %lld\n", print_event_info->row_events);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

row_events is ulonglong, that is unsigned. Were you getting a compiler error here?

you wrote it's a non-goal, so I will no longer comment on signed/unsigned mismatch, but would the code compile without you fixing it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it’s impractical to track typedefs manually when we can automatically catch them by turning on -Wformat-signedness, so I explicitly excluded this step.

From what I can tell, neither -Wformat nor -Wall include -Wformat-signedness, so issues like this continue not spawning compile warnings.

I mentioned -Wformat-signedness as a comment of MDEV-26896.
We can prioritize it here or we can push for MDEV-26896 to ship with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Turning on -Wconversion (MDEV-26896) will complain about cases like these before this replacement.
🧐 It will also complain about char *ullstr(longlong value,char *buff) because it delegates a ulonglong arg to longlong10_to_str(value,buff,10); which is sign-agnostic.

print_event_info->row_events= 0;
}
return result;
Expand Down Expand Up @@ -863,7 +861,6 @@ static inline my_bool is_server_id_excluded(uint32 server_id)
Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev,
my_off_t pos, const char *logname)
{
char ll_buff[21];
Log_event_type ev_type= ev->get_type_code();
my_bool destroy_evt= TRUE;
my_bool gtid_err= FALSE;
Expand Down Expand Up @@ -1040,7 +1037,7 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev,
goto end;
}
if (print_row_event_positions)
fprintf(result_file, "# at %s\n",llstr(pos,ll_buff));
fprintf(result_file, "# at %lld\n", pos);

if (!opt_hexdump)
print_event_info->hexdump_from= 0; /* Disabled */
Expand Down Expand Up @@ -3160,7 +3157,6 @@ static Exit_status dump_local_log_entries(PRINT_EVENT_INFO *print_event_info,
}
for (;;)
{
char llbuff[21];
my_off_t old_off = my_b_tell(file);

Log_event* ev = Log_event::read_log_event(file, glob_description_event,
Expand All @@ -3175,9 +3171,8 @@ static Exit_status dump_local_log_entries(PRINT_EVENT_INFO *print_event_info,
file->error= 0;
else if (file->error)
{
error("Could not read entry at offset %s: "
"Error in log format or read error.",
llstr(old_off,llbuff));
error("Could not read entry at offset %lld: "
"Error in log format or read error.", old_off);
goto err;
}
// else file->error == 0 means EOF, that's OK, we break in this case
Expand Down
4 changes: 2 additions & 2 deletions client/mysqltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7991,8 +7991,8 @@ void append_metadata(DYNAMIC_STRING *ds,
void append_info(DYNAMIC_STRING *ds, ulonglong affected_rows,
const char *info)
{
char buf[40], buff2[21];
size_t len= sprintf(buf,"affected rows: %s\n", llstr(affected_rows, buff2));
char buf[40];
size_t len= sprintf(buf,"affected rows: %lld\n", affected_rows);
dynstr_append_mem(ds, buf, len);
if (info)
{
Expand Down
2 changes: 0 additions & 2 deletions include/m_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ size_t my_gcvt(double x, my_gcvt_arg_type type, int width, char *to,
*/
#define MY_GCVT_MAX_FIELD_WIDTH (DBL_DIG + 4 + MY_MAX(5, MAX_DECPT_FOR_F_FORMAT)) \

extern char *llstr(longlong value,char *buff);
extern char *ullstr(longlong value,char *buff);
#ifndef HAVE_STRTOUL
extern long strtol(const char *str, char **ptr, int base);
extern ulong strtoul(const char *str, char **ptr, int base);
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/main/func_misc.result
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ SELECT GET_LOCK('ul1', -1);
GET_LOCK('ul1', -1)
NULL
Warnings:
Warning 1411 Incorrect timeout value: '-1' for function get_lock
Warning 1411 Incorrect timeout value: '-1.000000' for function get_lock
#
# MDEV-8624 MariaDB hangs on query with many logical condition
#
Expand Down
6 changes: 2 additions & 4 deletions mysys/mf_iocache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1920,7 +1920,6 @@ int main(int argc, char** argv)
MY_STAT status;
const char* fname="/tmp/iocache.test";
int cache_size=16384;
char llstr_buf[22];
int max_block,total_bytes=0;
int i,num_loops=100,error=0;
char *p;
Expand Down Expand Up @@ -1955,9 +1954,8 @@ int main(int argc, char** argv)
if (!my_stat(fname,&status,MYF(MY_WME)))
die("%s failed to stat, but I had just closed it,\
wonder how that happened");
printf("Final size of %s is %s, wrote %d bytes\n",fname,
llstr(status.st_size,llstr_buf),
total_bytes);
printf("Final size of %s is %lld, wrote %d bytes\n",
fname, status.st_size, total_bytes);
my_delete(fname, MYF(MY_WME));
/* check correctness of tests */
if (total_bytes != status.st_size)
Expand Down
16 changes: 6 additions & 10 deletions mysys/my_getopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,6 @@ longlong getopt_ll_limit_value(longlong num, const struct my_option *optp,
{
longlong old= num;
my_bool adjusted= FALSE;
char buf1[255], buf2[255];
ulonglong block_size= (optp->block_size ? (ulonglong) optp->block_size : 1L);
DBUG_ENTER("getopt_ll_limit_value");

Expand Down Expand Up @@ -1238,8 +1237,8 @@ longlong getopt_ll_limit_value(longlong num, const struct my_option *optp,
*fix= old != num;
else if (adjusted)
my_getopt_error_reporter(WARNING_LEVEL,
"option '%s': signed value %s adjusted to %s",
optp->name, llstr(old, buf1), llstr(num, buf2));
"option '%s': signed value %lld adjusted to %lld",
optp->name, old, num);
DBUG_RETURN(num);
}

Expand All @@ -1264,7 +1263,6 @@ ulonglong getopt_ull_limit_value(ulonglong num, const struct my_option *optp,
{
my_bool adjusted= FALSE;
ulonglong old= num;
char buf1[255], buf2[255];
DBUG_ENTER("getopt_ull_limit_value");

if ((ulonglong) num > (ulonglong) optp->max_value &&
Expand Down Expand Up @@ -1313,8 +1311,8 @@ ulonglong getopt_ull_limit_value(ulonglong num, const struct my_option *optp,
*fix= old != num;
else if (adjusted)
my_getopt_error_reporter(WARNING_LEVEL,
"option '%s': unsigned value %s adjusted to %s",
optp->name, ullstr(old, buf1), ullstr(num, buf2));
"option '%s': unsigned value %llu adjusted to %llu",
optp->name, old, num);

DBUG_RETURN(num);
}
Expand Down Expand Up @@ -1730,7 +1728,6 @@ void my_print_variables(const struct my_option *options)
{
uint name_space= 34, length, nr;
ulonglong llvalue;
char buff[255];
const struct my_option *optp;
DBUG_ENTER("my_print_variables");

Expand Down Expand Up @@ -1811,11 +1808,10 @@ void my_print_variables(const struct my_option *options)
printf("%lu\n", *((ulong*) value));
break;
case GET_LL:
printf("%s\n", llstr(*((longlong*) value), buff));
printf("%lld\n", *((longlong*) value));
break;
case GET_ULL:
longlong10_to_str(*((ulonglong*) value), buff, 10);
printf("%s\n", buff);
printf("%llu\n", *((ulonglong*) value));
break;
case GET_DOUBLE:
printf("%.10g\n", *(double*) value);
Expand Down
7 changes: 3 additions & 4 deletions sql/item_func.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4275,14 +4275,13 @@ longlong Item_func_get_lock::val_int()
DBUG_RETURN(1);
}

if (args[1]->null_value ||
(!args[1]->unsigned_flag && ((longlong) timeout < 0)))
if (args[1]->null_value || (!args[1]->unsigned_flag && timeout < 0.0))
{
char buf[22];
if (args[1]->null_value)
strmov(buf, "NULL");
else
llstr(((longlong) timeout), buf);
snprintf(buf, sizeof(buf), "%lf", timeout);
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_WRONG_VALUE_FOR_TYPE, ER(ER_WRONG_VALUE_FOR_TYPE),
"timeout", buf, "get_lock");
Expand Down Expand Up @@ -4523,7 +4522,7 @@ longlong Item_func_benchmark::val_int()
if (!args[0]->null_value)
{
char buff[22];
llstr(((longlong) loop_count), buff);
longlong10_to_str(loop_count, buff, -10);
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_WRONG_VALUE_FOR_TYPE,
ER_THD(thd, ER_WRONG_VALUE_FOR_TYPE),
Expand Down
9 changes: 4 additions & 5 deletions sql/log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3336,7 +3336,6 @@ bool MYSQL_QUERY_LOG::write(THD *thd, time_t current_time,
const char *sql_text, size_t sql_text_len)
{
bool error= 0;
char llbuff[22];
DBUG_ENTER("MYSQL_QUERY_LOG::write");

mysql_mutex_lock(&LOCK_log);
Expand Down Expand Up @@ -3422,15 +3421,15 @@ bool MYSQL_QUERY_LOG::write(THD *thd, time_t current_time,
if (thd->tmp_tables_used &&
my_b_printf(&log_file,
"# Tmp_tables: %lu Tmp_disk_tables: %lu "
"Tmp_table_sizes: %s\n",
"Tmp_table_sizes: %lld\n",
(ulong) thd->tmp_tables_used,
(ulong) thd->tmp_tables_disk_used,
llstr(thd->tmp_tables_size, llbuff)))
thd->tmp_tables_size))
goto err;
if (thd->max_tmp_space_used &&
my_b_printf(&log_file,
"# Max_tmp_disk_space_used: %s\n",
llstr(thd->max_tmp_space_used, llbuff)))
"# Max_tmp_disk_space_used: %lld\n",
thd->max_tmp_space_used))
goto err;
}

Expand Down
7 changes: 2 additions & 5 deletions sql/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -936,13 +936,10 @@ class MYSQL_BIN_LOG: public TC_LOG, private Event_log
}
void harvest_bytes_written(Atomic_counter<uint64> *counter)
{
#ifdef DBUG_TRACE
char buf1[22],buf2[22];
#endif
DBUG_ENTER("harvest_bytes_written");
(*counter)+=bytes_written;
DBUG_PRINT("info",("counter: %s bytes_written: %s", llstr(*counter,buf1),
llstr(bytes_written,buf2)));
DBUG_PRINT("info",
("counter: %lld bytes_written: %lld", *counter, bytes_written));
bytes_written=0;
DBUG_VOID_RETURN;
}
Expand Down
Loading