From 0f1e3da5deae77c100ed3d72243208d63ae4c1db Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 23 May 2013 19:30:58 +0100 Subject: [PATCH] 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. --- .../test-suite/python/python_varargs_typemap_runme.py | 3 +++ Examples/test-suite/python_varargs_typemap.i | 8 ++++++-- Source/Modules/python.cxx | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Examples/test-suite/python/python_varargs_typemap_runme.py b/Examples/test-suite/python/python_varargs_typemap_runme.py index 3c3f042eb..79479e449 100644 --- a/Examples/test-suite/python/python_varargs_typemap_runme.py +++ b/Examples/test-suite/python/python_varargs_typemap_runme.py @@ -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!") diff --git a/Examples/test-suite/python_varargs_typemap.i b/Examples/test-suite/python_varargs_typemap.i index 4bc6f3fbd..09189f654 100644 --- a/Examples/test-suite/python_varargs_typemap.i +++ b/Examples/test-suite/python_varargs_typemap.i @@ -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; } } diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index e3d8c7d50..9a068a40a 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -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");