summaryrefslogtreecommitdiff
path: root/sprintf.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-08-20 01:43:04 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-08-20 10:06:16 +0900
commitd2483393cbcb4dcfa0000fa8166bb7fa7ed9f7b4 (patch)
tree5db32cf5e09b6aaddf4161e37e81d4cd961a71b8 /sprintf.c
parent8f4a53d0517a99e57060211a3efe2d7a9d5d06b2 (diff)
downloadruby-d2483393cbcb4dcfa0000fa8166bb7fa7ed9f7b4.tar.gz
[Bug #18956] Negative codepoints are invalid characters
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/sprintf.c b/sprintf.c
index 22edf398fe..f7ebe82e2c 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -447,8 +447,8 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
goto format_s1;
}
else {
- c = NUM2INT(val);
- n = rb_enc_codelen(c, enc);
+ n = NUM2INT(val);
+ if (n >= 0) n = rb_enc_codelen((c = n), enc);
}
if (n <= 0) {
rb_raise(rb_eArgError, "invalid character");