summaryrefslogtreecommitdiff
path: root/sprintf.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-08-20 00:16:43 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-08-20 03:57:13 +0900
commitce384ef5a95b809f248e089c1608e60753dabe45 (patch)
tree8628b9c8480e6f0601f5e4a540781a4edfeadc30 /sprintf.c
parent4177f60eedd71b846d9a86889fd46071ecdb0158 (diff)
[Bug #18955] Check length of argument for `%c` in proper encoding
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6258
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/sprintf.c b/sprintf.c
index b16ab3f581..5f7227e619 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -441,10 +441,11 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
tmp = rb_check_string_type(val);
if (!NIL_P(tmp)) {
- if (rb_enc_strlen(RSTRING_PTR(tmp),RSTRING_END(tmp),enc) != 1) {
+ rb_encoding *valenc = rb_enc_get(tmp);
+ if (rb_enc_strlen(RSTRING_PTR(tmp), RSTRING_END(tmp), valenc) != 1) {
rb_raise(rb_eArgError, "%%c requires a character");
}
- c = rb_enc_codepoint_len(RSTRING_PTR(tmp), RSTRING_END(tmp), &n, enc);
+ c = rb_enc_codepoint_len(RSTRING_PTR(tmp), RSTRING_END(tmp), &n, valenc);
RB_GC_GUARD(tmp);
}
else {