ext/yajl/yajl_ext.c in yajl-ruby-1.2.0 vs ext/yajl/yajl_ext.c in yajl-ruby-1.2.1

- old
+ new

@@ -273,21 +273,22 @@ yajl_check_and_fire_callback(ctx); return 1; } static int yajl_found_number(void * ctx, const char * numberVal, unsigned int numberLen) { - char buf[numberLen+1]; + char* buf = (char*)malloc(numberLen + 1); buf[numberLen] = 0; memcpy(buf, numberVal, numberLen); if (memchr(buf, '.', numberLen) || memchr(buf, 'e', numberLen) || memchr(buf, 'E', numberLen)) { yajl_set_static_value(ctx, rb_float_new(strtod(buf, NULL))); } else { yajl_set_static_value(ctx, rb_cstr2inum(buf, 10)); } + free(buf); return 1; } static int yajl_found_string(void * ctx, const unsigned char * stringVal, unsigned int stringLen) { VALUE str = rb_str_new((const char *)stringVal, stringLen); @@ -313,28 +314,26 @@ #ifdef HAVE_RUBY_ENCODING_H default_internal_enc = rb_default_internal_encoding(); #endif if (wrapper->symbolizeKeys) { - char buf[stringLen+1]; - memcpy(buf, stringVal, stringLen); - buf[stringLen] = 0; - VALUE stringEncoded = rb_str_new2(buf); #ifdef HAVE_RUBY_ENCODING_H - rb_enc_associate(stringEncoded, rb_utf8_encoding()); + ID id = rb_intern3((const char *)stringVal, stringLen, utf8Encoding); + keyStr = ID2SYM(id); +#else + VALUE str = rb_str_new((const char *)stringVal, stringLen); + keyStr = rb_str_intern(str); #endif - - yajl_set_static_value(ctx, ID2SYM(rb_to_id(stringEncoded))); } else { keyStr = rb_str_new((const char *)stringVal, stringLen); #ifdef HAVE_RUBY_ENCODING_H rb_enc_associate(keyStr, utf8Encoding); if (default_internal_enc) { keyStr = rb_str_export_to_enc(keyStr, default_internal_enc); } #endif - yajl_set_static_value(ctx, keyStr); } + yajl_set_static_value(ctx, keyStr); yajl_check_and_fire_callback(ctx); return 1; } static int yajl_found_start_hash(void * ctx) {