Make 'rb_get_args()' va_arg passing safer by introducing a termination marker

What can I say. I made a pact with the devil, and paid dearly.
Almost a whole day's worth of debugging, actually. Not again.

If this turns out to be slow we can always optimize the critical
parts (with no variable param count) later, or completely remove it.
This commit is contained in:
Jonas Kulla 2013-09-27 04:49:48 +02:00
parent 92525cd077
commit 4ff563725b
15 changed files with 92 additions and 48 deletions

View file

@ -282,10 +282,51 @@ rb_get_args(int argc, VALUE *argv, const char *format, ...)
}
}
/* Pop remaining arg pointers off
* the stack to check for RB_ARG_END */
format--;
while ((c = *format++))
{
switch (c)
{
case 'o' :
case 'S' :
va_arg(ap, VALUE*);
break;
case 's' :
va_arg(ap, const char**);
va_arg(ap, int*);
break;
case 'z' :
va_arg(ap, const char**);
break;
case 'f' :
va_arg(ap, double*);
break;
case 'i' :
va_arg(ap, int*);
break;
case 'b' :
va_arg(ap, bool*);
break;
}
}
// FIXME print num of needed args vs provided
if (!c && argc > argI)
rb_raise(rb_eArgError, "wrong number of arguments");
/* Verify correct termination */
void *argEnd = va_arg(ap, void*);
Q_UNUSED(argEnd);
Q_ASSERT(argEnd == RB_ARG_END);
va_end(ap);
return argI;