summaryrefslogtreecommitdiff
path: root/ext/json/generator/generator.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-20 02:55:08 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-20 02:55:08 +0000
commit14cab32596d3e394cafea7a7698a81034b83c172 (patch)
tree672a0450700e77f4d0129f781ce24c1799a773fa /ext/json/generator/generator.c
parent9d740ddebeaa46f47c9b4529e8b36d72d97f9105 (diff)
* ext/json: merge JSON 1.8.1.
https://github.com/nurse/json/compare/002ac2771ce32776b32ccd2d06e5604de6c36dcd...e09ffc0d7da25d0393873936c118c188c78dbac3 * Remove Rubinius exception since transcoding should be working now. * Fix https://github.com/flori/json/issues/162 reported by Marc-Andre Lafortune <github_rocks@marc-andre.ca>. Thanks! * Applied patches by Yui NARUSE <naruse@airemix.jp> to suppress warning with -Wchar-subscripts and better validate UTF-8 strings. * Applied patch by ginriki@github to remove unnecessary if. * Add load/dump interface to JSON::GenericObject to make serialize :some_attribute, JSON::GenericObject work in Rails active models for convenient SomeModel#some_attribute.foo.bar access to serialised JSON data. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43731 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/json/generator/generator.c')
-rw-r--r--ext/json/generator/generator.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/ext/json/generator/generator.c b/ext/json/generator/generator.c
index 40c9e1e6df..ed7bb82887 100644
--- a/ext/json/generator/generator.c
+++ b/ext/json/generator/generator.c
@@ -273,7 +273,18 @@ static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string)
escape_len = 2;
break;
default:
- end++;
+ {
+ unsigned short clen = trailingBytesForUTF8[c] + 1;
+ if (end + clen > len) {
+ rb_raise(rb_path2class("JSON::GeneratorError"),
+ "partial character in source, but hit end");
+ }
+ if (!isLegalUTF8((UTF8 *) p, clen)) {
+ rb_raise(rb_path2class("JSON::GeneratorError"),
+ "source sequence is illegal/malformed utf-8");
+ }
+ end += clen;
+ }
continue;
break;
}
@@ -288,7 +299,7 @@ static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string)
static char *fstrndup(const char *ptr, unsigned long len) {
char *result;
- if (len == 0) return NULL;
+ if (len <= 0) return NULL;
result = ALLOC_N(char, len);
memccpy(result, ptr, 0, len);
return result;
@@ -511,11 +522,8 @@ static VALUE cState_configure(VALUE self, VALUE opts)
{
VALUE tmp;
GET_STATE(self);
- tmp = rb_convert_type(opts, T_HASH, "Hash", "to_hash");
+ tmp = rb_check_convert_type(opts, T_HASH, "Hash", "to_hash");
if (NIL_P(tmp)) tmp = rb_convert_type(opts, T_HASH, "Hash", "to_h");
- if (NIL_P(tmp)) {
- rb_raise(rb_eArgError, "opts has to be hash like or convertable into a hash");
- }
opts = tmp;
tmp = rb_hash_aref(opts, ID2SYM(i_indent));
if (RTEST(tmp)) {
@@ -1178,11 +1186,11 @@ static VALUE cState_array_nl_set(VALUE self, VALUE array_nl)
/*
- * call-seq: check_circular?
- *
- * Returns true, if circular data structures should be checked,
- * otherwise returns false.
- */
+* call-seq: check_circular?
+*
+* Returns true, if circular data structures should be checked,
+* otherwise returns false.
+*/
static VALUE cState_check_circular_p(VALUE self)
{
GET_STATE(self);