Fix the high passed to PyTuple_GetSlice in varargs wrappers.

Harmless bug as slices can take any size larger than the actual size for
the high value. Reported in SF Bug 1326.
This commit is contained in:
William S Fulton 2013-05-23 19:30:58 +01:00
commit 0f1e3da5de
3 changed files with 10 additions and 3 deletions

View file

@ -2,3 +2,6 @@ import python_varargs_typemap
if (python_varargs_typemap.testfunc(1, 2.0, "three") != "three") :
raise RuntimeError("testfunc failed!")
if (python_varargs_typemap.testfunc(1, 2.0, "three", "four", "five") != "threefourfive") :
raise RuntimeError("testfunc failed!")

View file

@ -51,10 +51,14 @@ char* testfunc (int arg1, double arg2, ...)
{
va_list ap;
char *c;
static char buffer[1024];
buffer[0] = 0;
va_start(ap, arg2);
c = va_arg(ap, char*);
while ((c = va_arg(ap, char *))) {
strcat(buffer, c);
}
va_end(ap);
return c;
return buffer;
}
}

View file

@ -2614,7 +2614,7 @@ public:
Printf(f->code, "}\n");
} else {
Printf(f->code, "newargs = PyTuple_GetSlice(args,0,%d);\n", num_fixed_arguments);
Printf(f->code, "varargs = PyTuple_GetSlice(args,%d,PyTuple_Size(args)+1);\n", num_fixed_arguments);
Printf(f->code, "varargs = PyTuple_GetSlice(args,%d,PyTuple_Size(args));\n", num_fixed_arguments);
}
Printf(f->code, "resultobj = %s__varargs__(%s,newargs,varargs);\n", wname, builtin ? "self" : "NULL");
Append(f->code, "Py_XDECREF(newargs);\n");