mirror of
https://github.com/MariaDB/server.git
synced 2025-08-17 21:39:33 +00:00
Merge vsnprintf
%b
, %T
& %M
code into %s
/%u
This commit prepares for MDEV-21978 which wants to migrate extensions from *specifiers* to standard-compatible *suffixes*, complete with boolean local vars. In this new format, branches will land on `%s`/`%u` before processing the suffix. This commit contains non-breaking portions of MDEV-21978 work. This commit also changes an `if`-`else` chain to a `switch` block simply because it’s an eyesore.
This commit is contained in:

committed by
Sergei Golubchik

parent
9799777992
commit
06851e7f77
@ -521,27 +521,24 @@ start:
|
|||||||
switch (print_arr[i].arg_type) {
|
switch (print_arr[i].arg_type) {
|
||||||
case 's':
|
case 's':
|
||||||
case 'T':
|
case 'T':
|
||||||
{
|
|
||||||
longlong min_field_width;
|
|
||||||
char *par= args_arr[print_arr[i].arg_idx].str_arg;
|
|
||||||
width= (print_arr[i].flags & WIDTH_ARG)
|
|
||||||
? (size_t)args_arr[print_arr[i].width].longlong_arg
|
|
||||||
: print_arr[i].width;
|
|
||||||
min_field_width= (print_arr[i].flags & LENGTH_ARG)
|
|
||||||
? args_arr[print_arr[i].length].longlong_arg
|
|
||||||
: (longlong) print_arr[i].length;
|
|
||||||
to= process_str_arg(cs, to, end, min_field_width, width, par,
|
|
||||||
print_arr[i].flags,
|
|
||||||
(print_arr[i].arg_type == 'T'));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'b':
|
case 'b':
|
||||||
{
|
{
|
||||||
char *par = args_arr[print_arr[i].arg_idx].str_arg;
|
char *par= args_arr[print_arr[i].arg_idx].str_arg;
|
||||||
|
my_bool suffix_b= print_arr[i].arg_type == 'b';
|
||||||
|
my_bool suffix_t= print_arr[i].arg_type == 'T';
|
||||||
width= (print_arr[i].flags & WIDTH_ARG)
|
width= (print_arr[i].flags & WIDTH_ARG)
|
||||||
? (size_t)args_arr[print_arr[i].width].longlong_arg
|
? (size_t)args_arr[print_arr[i].width].longlong_arg
|
||||||
: print_arr[i].width;
|
: print_arr[i].width;
|
||||||
to= process_bin_arg(to, end, width, par);
|
if (suffix_b)
|
||||||
|
to= process_bin_arg(to, end, width, par);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
longlong min_field_width= (print_arr[i].flags & LENGTH_ARG)
|
||||||
|
? args_arr[print_arr[i].length].longlong_arg
|
||||||
|
: (longlong) print_arr[i].length;
|
||||||
|
to= process_str_arg(cs, to, end, min_field_width, width, par,
|
||||||
|
print_arr[i].flags, suffix_t);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'c':
|
case 'c':
|
||||||
@ -567,40 +564,37 @@ start:
|
|||||||
case 'X':
|
case 'X':
|
||||||
case 'o':
|
case 'o':
|
||||||
case 'p':
|
case 'p':
|
||||||
{
|
|
||||||
/* Integer parameter */
|
|
||||||
longlong larg;
|
|
||||||
length= (print_arr[i].flags & LENGTH_ARG)
|
|
||||||
? (size_t)args_arr[print_arr[i].length].longlong_arg
|
|
||||||
: print_arr[i].length;
|
|
||||||
|
|
||||||
larg = args_arr[print_arr[i].arg_idx].longlong_arg;
|
|
||||||
to= process_int_arg(to, end, length, larg, print_arr[i].arg_type,
|
|
||||||
print_arr[i].flags);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'M':
|
case 'M':
|
||||||
{
|
{
|
||||||
longlong larg;
|
/* Integer parameter */
|
||||||
const char *real_end;
|
longlong larg= args_arr[print_arr[i].arg_idx].longlong_arg;
|
||||||
|
my_bool suffix_e= print_arr[i].arg_type == 'M';
|
||||||
width= (print_arr[i].flags & WIDTH_ARG)
|
if (suffix_e)
|
||||||
? (size_t)args_arr[print_arr[i].width].longlong_arg
|
|
||||||
: print_arr[i].width;
|
|
||||||
|
|
||||||
real_end= MY_MIN(to + width, end);
|
|
||||||
|
|
||||||
larg = args_arr[print_arr[i].arg_idx].longlong_arg;
|
|
||||||
to= process_int_arg(to, real_end, 0, larg, 'd', print_arr[i].flags);
|
|
||||||
if (real_end - to >= 3)
|
|
||||||
{
|
{
|
||||||
char errmsg_buff[MYSYS_STRERROR_SIZE];
|
const char *real_end;
|
||||||
*to++= ' ';
|
width= (print_arr[i].flags & WIDTH_ARG)
|
||||||
*to++= '"';
|
? (size_t)args_arr[print_arr[i].width].longlong_arg
|
||||||
my_strerror(errmsg_buff, sizeof(errmsg_buff), (int) larg);
|
: print_arr[i].width;
|
||||||
to= process_str_arg(cs, to, real_end, 0, width, errmsg_buff,
|
real_end= MY_MIN(to + width, end);
|
||||||
print_arr[i].flags, 1);
|
to= process_int_arg(to, real_end, 0, larg, 'd', print_arr[i].flags);
|
||||||
if (real_end > to) *to++= '"';
|
if (real_end - to >= 3)
|
||||||
|
{
|
||||||
|
char errmsg_buff[MYSYS_STRERROR_SIZE];
|
||||||
|
*to++= ' ';
|
||||||
|
*to++= '"';
|
||||||
|
my_strerror(errmsg_buff, sizeof(errmsg_buff), (int) larg);
|
||||||
|
to= process_str_arg(cs, to, real_end, 0, width, errmsg_buff,
|
||||||
|
print_arr[i].flags, 1);
|
||||||
|
if (real_end > to)
|
||||||
|
*to++= '"';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
length= (print_arr[i].flags & LENGTH_ARG)
|
||||||
|
? (size_t)args_arr[print_arr[i].length].longlong_arg
|
||||||
|
: print_arr[i].length;
|
||||||
|
to= process_int_arg(to, end, length, larg, print_arr[i].arg_type,
|
||||||
|
print_arr[i].flags);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -723,20 +717,22 @@ size_t my_vsnprintf_ex(CHARSET_INFO *cs, char *to, size_t n,
|
|||||||
|
|
||||||
fmt= check_longlong(fmt, &have_longlong);
|
fmt= check_longlong(fmt, &have_longlong);
|
||||||
|
|
||||||
if (*fmt == 's' || *fmt == 'T') /* String parameter */
|
switch(*fmt) {
|
||||||
|
case 's':
|
||||||
|
case 'T':
|
||||||
|
case 'b':
|
||||||
{
|
{
|
||||||
|
/* String parameter */
|
||||||
reg2 char *par= va_arg(ap, char *);
|
reg2 char *par= va_arg(ap, char *);
|
||||||
to= process_str_arg(cs, to, end, (longlong) length, width, par,
|
my_bool suffix_b= *fmt == 'b', suffix_t= *fmt == 'T';
|
||||||
print_type, (*fmt == 'T'));
|
to= (suffix_b)
|
||||||
|
? process_bin_arg(to, end, width, par)
|
||||||
|
: process_str_arg(cs, to, end, (longlong) length, width, par,
|
||||||
|
print_type, suffix_t);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (*fmt == 'b') /* Buffer parameter */
|
case 'f':
|
||||||
{
|
case 'g':
|
||||||
char *par = va_arg(ap, char *);
|
|
||||||
to= process_bin_arg(to, end, width, par);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else if (*fmt == 'f' || *fmt == 'g')
|
|
||||||
{
|
{
|
||||||
double d;
|
double d;
|
||||||
#if __has_feature(memory_sanitizer) /* QQ: MSAN has double trouble? */
|
#if __has_feature(memory_sanitizer) /* QQ: MSAN has double trouble? */
|
||||||
@ -749,23 +745,45 @@ size_t my_vsnprintf_ex(CHARSET_INFO *cs, char *to, size_t n,
|
|||||||
to= process_dbl_arg(to, end, width, d, *fmt);
|
to= process_dbl_arg(to, end, width, d, *fmt);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (*fmt == 'd' || *fmt == 'i' || *fmt == 'u' || *fmt == 'x' ||
|
case 'd':
|
||||||
*fmt == 'X' || *fmt == 'p' || *fmt == 'o')
|
case 'i':
|
||||||
|
case 'u':
|
||||||
|
case 'x':
|
||||||
|
case 'X':
|
||||||
|
case 'o':
|
||||||
|
case 'p':
|
||||||
|
case 'M':
|
||||||
{
|
{
|
||||||
/* Integer parameter */
|
/* Integer parameter */
|
||||||
longlong larg;
|
longlong larg;
|
||||||
|
my_bool suffix_e= *fmt == 'M';
|
||||||
if (have_longlong)
|
if (have_longlong)
|
||||||
larg = va_arg(ap,longlong);
|
larg = va_arg(ap,longlong);
|
||||||
else if (*fmt == 'd' || *fmt == 'i')
|
else if (*fmt == 'd' || *fmt == 'i' || suffix_e)
|
||||||
larg = va_arg(ap, int);
|
larg = va_arg(ap, int);
|
||||||
else
|
else
|
||||||
larg= va_arg(ap, uint);
|
larg= va_arg(ap, uint);
|
||||||
|
if (suffix_e)
|
||||||
to= process_int_arg(to, end, length, larg, *fmt, print_type);
|
{
|
||||||
|
const char *real_end= MY_MIN(to + width, end);
|
||||||
|
to= process_int_arg(to, real_end, 0, larg, 'd', print_type);
|
||||||
|
if (real_end - to >= 3)
|
||||||
|
{
|
||||||
|
char errmsg_buff[MYSYS_STRERROR_SIZE];
|
||||||
|
*to++= ' ';
|
||||||
|
*to++= '"';
|
||||||
|
my_strerror(errmsg_buff, sizeof(errmsg_buff), (int) larg);
|
||||||
|
to= process_str_arg(cs, to, real_end, 0, width, errmsg_buff,
|
||||||
|
print_type, 1);
|
||||||
|
if (real_end > to)
|
||||||
|
*to++= '"';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
to= process_int_arg(to, end, length, larg, *fmt, print_type);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (*fmt == 'c') /* Character parameter */
|
case 'c': /* Character parameter */
|
||||||
{
|
{
|
||||||
register int larg;
|
register int larg;
|
||||||
if (to == end)
|
if (to == end)
|
||||||
@ -774,23 +792,6 @@ size_t my_vsnprintf_ex(CHARSET_INFO *cs, char *to, size_t n,
|
|||||||
*to++= (char) larg;
|
*to++= (char) larg;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (*fmt == 'M')
|
|
||||||
{
|
|
||||||
int larg= va_arg(ap, int);
|
|
||||||
const char *real_end= MY_MIN(to + width, end);
|
|
||||||
|
|
||||||
to= process_int_arg(to, real_end, 0, larg, 'd', print_type);
|
|
||||||
if (real_end - to >= 3)
|
|
||||||
{
|
|
||||||
char errmsg_buff[MYSYS_STRERROR_SIZE];
|
|
||||||
*to++= ' ';
|
|
||||||
*to++= '"';
|
|
||||||
my_strerror(errmsg_buff, sizeof(errmsg_buff), (int) larg);
|
|
||||||
to= process_str_arg(cs, to, real_end, 0, width, errmsg_buff,
|
|
||||||
print_type, 1);
|
|
||||||
if (real_end > to) *to++= '"';
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We come here on '%%', unknown code or too long parameter */
|
/* We come here on '%%', unknown code or too long parameter */
|
||||||
|
Reference in New Issue
Block a user