summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-08 22:34:12 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-08 22:34:12 +0000
commite0f8351d5528cd01ab71855eae87ef067de55626 (patch)
tree3b259c3c1fb9703175ad43836cc4ef3210035797 /numeric.c
parent2bd2ea829f360bdae74281230aa3377b0c81fa14 (diff)
merge revision(s) 34236: [Backport #5890]
* numeric.c (rb_enc_uint_char): raise RangeError when added codepoint is invalid. [Feature #5855] [Bug #5863] [Bug #5864] * string.c (rb_str_concat): ditto. * string.c (rb_str_concat): set encoding as ASCII-8BIT when the string is US-ASCII and the argument is an integer greater than 127. * regenc.c (onigenc_mb2_code_to_mbclen): rearrange error code. * enc/euc_jp.c (code_to_mbclen): ditto. * enc/shift_jis.c (code_to_mbclen): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@34501 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/numeric.c b/numeric.c
index baa6a178e4..c05aaee8fd 100644
--- a/numeric.c
+++ b/numeric.c
@@ -2196,11 +2196,20 @@ rb_enc_uint_chr(unsigned int code, rb_encoding *enc)
{
int n;
VALUE str;
- if ((n = rb_enc_codelen(code, enc)) <= 0) {
+ switch (n = rb_enc_codelen(code, enc)) {
+ case ONIGERR_INVALID_CODE_POINT_VALUE:
+ rb_raise(rb_eRangeError, "invalid codepoint 0x%X in %s", code, rb_enc_name(enc));
+ break;
+ case ONIGERR_TOO_BIG_WIDE_CHAR_VALUE:
+ case 0:
rb_raise(rb_eRangeError, "%u out of char range", code);
+ break;
}
str = rb_enc_str_new(0, n, enc);
rb_enc_mbcput(code, RSTRING_PTR(str), enc);
+ if (rb_enc_precise_mbclen(RSTRING_PTR(str), RSTRING_END(str), enc) != n) {
+ rb_raise(rb_eRangeError, "invalid codepoint 0x%X in %s", code, rb_enc_name(enc));
+ }
return str;
}