mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Scan the code range of the formatted portion
This commit is contained in:
parent
59da26789f
commit
f34280ec6b
Notes:
git
2022-08-19 03:06:19 +09:00
1 changed files with 11 additions and 3 deletions
14
sprintf.c
14
sprintf.c
|
@ -1153,6 +1153,10 @@ ruby_vsprintf0(VALUE result, char *p, const char *fmt, va_list ap)
|
|||
rb_printf_buffer_extra buffer;
|
||||
#define f buffer.base
|
||||
VALUE klass = RBASIC(result)->klass;
|
||||
int coderange = ENC_CODERANGE(result);
|
||||
long scanned = 0;
|
||||
|
||||
if (coderange != ENC_CODERANGE_UNKNOWN) scanned = p - RSTRING_PTR(result);
|
||||
|
||||
f._flags = __SWR | __SSTR;
|
||||
f._bf._size = 0;
|
||||
|
@ -1165,9 +1169,13 @@ ruby_vsprintf0(VALUE result, char *p, const char *fmt, va_list ap)
|
|||
buffer.value = 0;
|
||||
BSD_vfprintf(&f, fmt, ap);
|
||||
RBASIC_SET_CLASS_RAW(result, klass);
|
||||
// vfprintf mutates the string without updating coderange
|
||||
ENC_CODERANGE_CLEAR(result);
|
||||
rb_str_resize(result, (char *)f._p - RSTRING_PTR(result));
|
||||
p = RSTRING_PTR(result);
|
||||
long blen = (char *)f._p - p;
|
||||
if (scanned < blen) {
|
||||
rb_str_coderange_scan_restartable(p + scanned, p + blen, rb_enc_get(result), &coderange);
|
||||
ENC_CODERANGE_SET(result, coderange);
|
||||
}
|
||||
rb_str_resize(result, blen);
|
||||
#undef f
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue