mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.2.3630: printf() with %S does not handle multi-byte correctly
Problem: Printf() with %S does not handle multi-byte correctly. Solution: Count cells instead of bytes. (closes #9169, closes #7486)
This commit is contained in:
parent
a119812437
commit
d85fccdfed
@ -2137,14 +2137,15 @@ vim_vsnprintf_typval(
|
|||||||
char *q = memchr(str_arg, '\0',
|
char *q = memchr(str_arg, '\0',
|
||||||
precision <= (size_t)0x7fffffffL ? precision
|
precision <= (size_t)0x7fffffffL ? precision
|
||||||
: (size_t)0x7fffffffL);
|
: (size_t)0x7fffffffL);
|
||||||
|
|
||||||
str_arg_l = (q == NULL) ? precision
|
str_arg_l = (q == NULL) ? precision
|
||||||
: (size_t)(q - str_arg);
|
: (size_t)(q - str_arg);
|
||||||
}
|
}
|
||||||
if (fmt_spec == 'S')
|
if (fmt_spec == 'S')
|
||||||
{
|
{
|
||||||
if (min_field_width != 0)
|
size_t base_width = min_field_width;
|
||||||
min_field_width += STRLEN(str_arg)
|
size_t pad_cell = 0;
|
||||||
- mb_string2cells((char_u *)str_arg, -1);
|
|
||||||
if (precision)
|
if (precision)
|
||||||
{
|
{
|
||||||
char_u *p1;
|
char_u *p1;
|
||||||
@ -2157,8 +2158,12 @@ vim_vsnprintf_typval(
|
|||||||
if (i > precision)
|
if (i > precision)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
str_arg_l = precision = p1 - (char_u *)str_arg;
|
pad_cell = min_field_width - precision;
|
||||||
|
base_width = str_arg_l = precision =
|
||||||
|
p1 - (char_u *)str_arg;
|
||||||
}
|
}
|
||||||
|
if (min_field_width != 0)
|
||||||
|
min_field_width = base_width + pad_cell;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -297,6 +297,11 @@ function Test_printf_misc()
|
|||||||
call assert_equal('🐍', printf('%.2S', '🐍🐍'))
|
call assert_equal('🐍', printf('%.2S', '🐍🐍'))
|
||||||
call assert_equal('', printf('%.1S', '🐍🐍'))
|
call assert_equal('', printf('%.1S', '🐍🐍'))
|
||||||
|
|
||||||
|
call assert_equal('[ あいう]', printf('[%10.6S]', 'あいうえお'))
|
||||||
|
call assert_equal('[ あいうえ]', printf('[%10.8S]', 'あいうえお'))
|
||||||
|
call assert_equal('[あいうえお]', printf('[%10.10S]', 'あいうえお'))
|
||||||
|
call assert_equal('[あいうえお]', printf('[%10.12S]', 'あいうえお'))
|
||||||
|
|
||||||
call assert_equal('1%', printf('%d%%', 1))
|
call assert_equal('1%', printf('%d%%', 1))
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
@ -757,6 +757,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
3630,
|
||||||
/**/
|
/**/
|
||||||
3629,
|
3629,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user