summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2011-07-08 16:41:47 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2011-07-08 16:41:47 +0900
commit10c6bfba2f03577ad3a5b7b1abff31a35378f45e (patch)
tree425d8b643da64966fc5db3006f84435122e07d81
parent62b2f6ab3c97697883c820cf13d6b8a85b1f053e (diff)
downloadjson-10c6bfba2f03577ad3a5b7b1abff31a35378f45e.tar.gz
Duplicate the argument of convert_encoding() only.
-rw-r--r--ext/json/ext/parser/parser.h2
-rw-r--r--ext/json/ext/parser/parser.rl1
2 files changed, 2 insertions, 1 deletions
diff --git a/ext/json/ext/parser/parser.h b/ext/json/ext/parser/parser.h
index f2ce5a4..2be640e 100644
--- a/ext/json/ext/parser/parser.h
+++ b/ext/json/ext/parser/parser.h
@@ -9,7 +9,7 @@
#ifdef HAVE_RUBY_ENCODING_H
#include "ruby/encoding.h"
-#define FORCE_UTF8(obj) ((obj) = rb_enc_associate(rb_str_dup(obj), rb_utf8_encoding()))
+#define FORCE_UTF8(obj) rb_enc_associate((obj), rb_utf8_encoding())
#else
#define FORCE_UTF8(obj)
#endif
diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl
index 3257a48..21b445e 100644
--- a/ext/json/ext/parser/parser.rl
+++ b/ext/json/ext/parser/parser.rl
@@ -581,6 +581,7 @@ static VALUE convert_encoding(VALUE source)
} else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16LE);
} else {
+ source = rb_str_dup(source);
FORCE_UTF8(source);
}
} else {