diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-04-16 07:12:06 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-04-16 07:12:06 +0000 |
commit | 7203a42c1099e206767f7b806fa2a2d82a33fd2f (patch) | |
tree | 347e43bc3698035793335c0297a158d2ecf1307a /string.c | |
parent | f0a6ab59eca18ca4203ced927cabb2261f154f8c (diff) | |
download | ruby-7203a42c1099e206767f7b806fa2a2d82a33fd2f.tar.gz |
string.c: fix dumped suffix
* string.c (rb_str_dump): get rid of an error on evaling with
frozen-string-literal enabled. [ruby-core:86539] [Bug #14687]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63164 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -5966,7 +5966,7 @@ rb_str_dump(VALUE str) char *q, *qend; VALUE result; int u8 = (encidx == rb_utf8_encindex()); - static const char nonascii_suffix[] = ".force_encoding(\"%s\")"; + static const char nonascii_suffix[] = ".dup.force_encoding(\"%s\")"; len = 2; /* "" */ if (!rb_enc_asciicompat(enc)) { @@ -6285,13 +6285,19 @@ str_undump(VALUE str) break; } else { + static const char force_encoding_suffix[] = ".force_encoding\(\""; + static const char dup_suffix[] = ".dup"; const char *encname; int encidx; ptrdiff_t size; - size = rb_strlen_lit(".force_encoding(\""); + /* check separately for strings dumped by older versions */ + size = sizeof(dup_suffix) - 1; + if (s_end - s > size && memcmp(s, dup_suffix, size) == 0) s += size; + + size = sizeof(force_encoding_suffix) - 1; if (s_end - s <= size) goto invalid_format; - if (memcmp(s, ".force_encoding(\"", size) != 0) goto invalid_format; + if (memcmp(s, force_encoding_suffix, size) != 0) goto invalid_format; s += size; if (utf8) { |