From 3f48c1fdf785f0d5a9939fc6163d9015d40e2b79 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 2 Jul 2014 08:03:53 +0000 Subject: 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 --- sprintf.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'sprintf.c') 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) { -- cgit v1.2.3