ext/oj/load.c in oj-0.5.2 vs ext/oj/load.c in oj-0.6.0
- old
+ new
@@ -104,21 +104,25 @@
}
}
}
VALUE
-parse(char *json, Options options) {
+oj_parse(char *json, Options options) {
VALUE obj;
struct _ParseInfo pi;
if (0 == json) {
raise_error("Invalid arg, xml string can not be null", json, 0);
}
/* initialize parse info */
pi.str = json;
pi.s = json;
+#ifdef HAVE_RUBY_ENCODING_H
pi.encoding = ('\0' == *options->encoding) ? 0 : rb_enc_find(options->encoding);
+#else
+ pi.encoding = 0;
+#endif
pi.options = options;
if (Qundef == (obj = read_next(&pi))) {
raise_error("no object read", pi.str, pi.s);
}
next_non_white(&pi); // skip white space
@@ -259,26 +263,47 @@
}
#endif
return s;
}
+#ifdef RUBINIUS
+#define NUM_MAX 0x07FFFFFF
+#else
+#define NUM_MAX (FIXNUM_MAX >> 8)
+#endif
+
static VALUE
read_num(ParseInfo pi) {
+ char *start = pi->s;
int64_t n = 0;
long a = 0;
long div = 1;
long e = 0;
int neg = 0;
int eneg = 0;
+ int big = 0;
if ('-' == *pi->s) {
pi->s++;
neg = 1;
} else if ('+' == *pi->s) {
pi->s++;
}
for (; '0' <= *pi->s && *pi->s <= '9'; pi->s++) {
n = n * 10 + (*pi->s - '0');
+ if (NUM_MAX <= n) {
+ big = 1;
+ }
+ }
+ if (big) {
+ char c = *pi->s;
+ VALUE num;
+
+ *pi->s = '\0';
+ num = rb_cstr_to_inum(start, 10, 0);
+ *pi->s = c;
+
+ return num;
}
if ('.' == *pi->s) {
pi->s++;
for (; '0' <= *pi->s && *pi->s <= '9'; pi->s++) {
a = a * 10 + (*pi->s - '0');