aboutsummaryrefslogtreecommitdiffstats
path: root/sprintf.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-02 08:03:53 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-02 08:03:53 +0000
commit3f48c1fdf785f0d5a9939fc6163d9015d40e2b79 (patch)
tree3ffabc3cc821b0afe8054ea33471d6119c933c3c /sprintf.c
parent420523389ec582f13924608ceb7640c95d7dd7a4 (diff)
downloadruby-3f48c1fdf785f0d5a9939fc6163d9015d40e2b79.tar.gz
sprintf.c: check_pos_arg
* sprintf.c (check_pos_arg): utility function for GETPOSARG(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/sprintf.c b/sprintf.c
index 8f715293a5..e7b9c1f17e 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -85,12 +85,9 @@ sign_bits(int base, const char *p)
check_next_arg(posarg, nextarg), \
(posarg = nextarg++, GETNTHARG(posarg)))
-#define GETPOSARG(n) (posarg > 0 ? \
- (rb_raise(rb_eArgError, "numbered(%d) after unnumbered(%d)", (n), posarg), 0) : \
- posarg == -2 ? \
- (rb_raise(rb_eArgError, "numbered(%d) after named", (n)), 0) : \
- (((n) < 1) ? (rb_raise(rb_eArgError, "invalid index - %d$", (n)), 0) : \
- (posarg = -1, GETNTHARG(n))))
+#define GETPOSARG(n) ( \
+ check_pos_arg(posarg, (n)), \
+ (posarg = -1, GETNTHARG(n)))
#define GETNTHARG(nth) \
(((nth) >= argc) ? (rb_raise(rb_eArgError, "too few arguments"), 0) : argv[(nth)])
@@ -150,6 +147,20 @@ check_next_arg(int posarg, int nextarg)
}
}
+static void
+check_pos_arg(int posarg, int n)
+{
+ if (posarg > 0) {
+ rb_raise(rb_eArgError, "numbered(%d) after unnumbered(%d)", n, posarg);
+ }
+ if (posarg == -2) {
+ rb_raise(rb_eArgError, "numbered(%d) after named", n);
+ }
+ if (n < 1) {
+ rb_raise(rb_eArgError, "invalid index - %d$", n);
+ }
+}
+
static VALUE
get_hash(volatile VALUE *hash, int argc, const VALUE *argv)
{