diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-06-06 13:37:23 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-06-06 13:37:23 +0000 |
commit | ce4a6e685d9b5847007321ed8984f0b8c27d3ebd (patch) | |
tree | 68d7deb20b362970d11105a6ac16cbb0450b51d1 /string.c | |
parent | 46880d476219811e14d54c3615c3d778321f7a6a (diff) |
* string.c (rb_str_buf_cat_escaped_char): get rid of buffer
overflow on platforms int is bigger than 32bit, and warnings.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@28190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -4081,9 +4081,14 @@ str_cat_char(VALUE str, unsigned int c, rb_encoding *enc) #define CHAR_ESC_LEN 13 /* sizeof(\x{ hex of 32bit unsigned int } \0) */ int -rb_str_buf_cat_escaped_char(VALUE result, unsigned int c, int unicode_p) { +rb_str_buf_cat_escaped_char(VALUE result, unsigned int c, int unicode_p) +{ char buf[CHAR_ESC_LEN + 1]; int l; + +#if SIZEOF_INT > 4 + c &= 0xffffffff; +#endif if (unicode_p) { if (c < 0x7F && ISPRINT(c)) { snprintf(buf, CHAR_ESC_LEN, "%c", c); @@ -4103,7 +4108,7 @@ rb_str_buf_cat_escaped_char(VALUE result, unsigned int c, int unicode_p) { snprintf(buf, CHAR_ESC_LEN, "\\x{%X}", c); } } - l = strlen(buf); + l = (int)strlen(buf); /* CHAR_ESC_LEN cannot exceed INT_MAX */ rb_str_buf_cat(result, buf, l); return l; } |