Mercurial > vim
comparison src/strings.c @ 26197:2093cc976da8 v8.2.3630
patch 8.2.3630: printf() with %S does not handle multi-byte correctly
Commit: https://github.com/vim/vim/commit/d85fccdfed58108c4e0958d0b17c64690b5f073f
Author: presuku <presuku@users.noreply.github.com>
Date: Sat Nov 20 19:38:31 2021 +0000
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 https://github.com/vim/vim/issues/9169, closes https://github.com/vim/vim/issues/7486)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 20 Nov 2021 20:45:02 +0100 |
parents | 454cbc872368 |
children | ce6490cd6282 |
comparison
equal
deleted
inserted
replaced
26196:75bc457099c4 | 26197:2093cc976da8 |
---|---|
2135 // macro. | 2135 // macro. |
2136 // memchr on HP does not like n > 2^31 !!! | 2136 // memchr on HP does not like n > 2^31 !!! |
2137 char *q = memchr(str_arg, '\0', | 2137 char *q = memchr(str_arg, '\0', |
2138 precision <= (size_t)0x7fffffffL ? precision | 2138 precision <= (size_t)0x7fffffffL ? precision |
2139 : (size_t)0x7fffffffL); | 2139 : (size_t)0x7fffffffL); |
2140 | |
2140 str_arg_l = (q == NULL) ? precision | 2141 str_arg_l = (q == NULL) ? precision |
2141 : (size_t)(q - str_arg); | 2142 : (size_t)(q - str_arg); |
2142 } | 2143 } |
2143 if (fmt_spec == 'S') | 2144 if (fmt_spec == 'S') |
2144 { | 2145 { |
2145 if (min_field_width != 0) | 2146 size_t base_width = min_field_width; |
2146 min_field_width += STRLEN(str_arg) | 2147 size_t pad_cell = 0; |
2147 - mb_string2cells((char_u *)str_arg, -1); | 2148 |
2148 if (precision) | 2149 if (precision) |
2149 { | 2150 { |
2150 char_u *p1; | 2151 char_u *p1; |
2151 size_t i = 0; | 2152 size_t i = 0; |
2152 | 2153 |
2155 { | 2156 { |
2156 i += (size_t)mb_ptr2cells(p1); | 2157 i += (size_t)mb_ptr2cells(p1); |
2157 if (i > precision) | 2158 if (i > precision) |
2158 break; | 2159 break; |
2159 } | 2160 } |
2160 str_arg_l = precision = p1 - (char_u *)str_arg; | 2161 pad_cell = min_field_width - precision; |
2162 base_width = str_arg_l = precision = | |
2163 p1 - (char_u *)str_arg; | |
2161 } | 2164 } |
2165 if (min_field_width != 0) | |
2166 min_field_width = base_width + pad_cell; | |
2162 } | 2167 } |
2163 break; | 2168 break; |
2164 | 2169 |
2165 default: | 2170 default: |
2166 break; | 2171 break; |