summaryrefslogtreecommitdiff
path: root/sprintf.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-08 08:04:12 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-08 08:04:12 +0000
commit8b427e357b707131614a45a3746dd06f9ac9a14b (patch)
tree9896de2916362e73ed86c4cc3fcaea74c605e602 /sprintf.c
parent286eaeb24f815211651e7443585188e42993eec1 (diff)
downloadruby-8b427e357b707131614a45a3746dd06f9ac9a14b.tar.gz
sprintf.c: skip non-interned name
* sprintf.c (rb_str_format): get rid of accessing by symbol of invalid ID, when the name is not interned. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/sprintf.c b/sprintf.c
index 27c477f5f5..6a2ee402aa 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -92,9 +92,9 @@ sign_bits(int base, const char *p)
#define GETNTHARG(nth) \
(((nth) >= argc) ? (rb_raise(rb_eArgError, "too few arguments"), 0) : argv[(nth)])
-#define GETNAMEARG(id, name, len, enc) ( \
+#define CHECKNAMEARG(name, len, enc) ( \
check_name_arg(posarg, name, len, enc), \
- (posarg = -2, rb_hash_lookup2(get_hash(&hash, argc, argv), (id), Qundef)))
+ posarg = -2)
#define GETNUM(n, val) \
(!(p = get_num(p, end, enc, &(n))) ? \
@@ -605,11 +605,12 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
rb_enc_raise(enc, rb_eArgError, "named%.*s after <%s>",
len, start, rb_id2name(id));
}
- nextvalue = GETNAMEARG((id = rb_check_id_cstr_without_pindown(start + 1,
- len - 2 /* without parenthesis */,
- enc),
- ID2SYM(id)),
- start, len, enc);
+ CHECKNAMEARG(start, len, enc);
+ get_hash(&hash, argc, argv);
+ id = rb_check_id_cstr_without_pindown(start + 1,
+ len - 2 /* without parenthesis */,
+ enc);
+ if (id) nextvalue = rb_hash_lookup2(hash, ID2SYM(id), Qundef);
if (nextvalue == Qundef) {
rb_enc_raise(enc, rb_eKeyError, "key%.*s not found", len, start);
}