summaryrefslogtreecommitdiffstats
path: root/Modules/socketmodule.c
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2011-05-07 16:21:22 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2011-05-07 16:21:22 (GMT)
commit0639be650511f717399e803faa798257b790ae81 (patch)
treeff785ab6bf8a943b71ce729ad7e00f2ae92f4c37 /Modules/socketmodule.c
parentcec464951e06dd9388352590eb1f17b9aa3d68a5 (diff)
downloadcpython-0639be650511f717399e803faa798257b790ae81.zip
cpython-0639be650511f717399e803faa798257b790ae81.tar.gz
cpython-0639be650511f717399e803faa798257b790ae81.tar.bz2
#10169: Fix argument parsing in socket.sendto() to avoid error masking.
Diffstat (limited to 'Modules/socketmodule.c')
-rw-r--r--Modules/socketmodule.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index d14910a..96b83b1 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -2826,14 +2826,24 @@ sock_sendto(PySocketSockObject *s, PyObject *args)
Py_ssize_t len;
sock_addr_t addrbuf;
int addrlen, n = -1, flags, timeout;
+ int arglen;
flags = 0;
- if (!PyArg_ParseTuple(args, "s*O:sendto", &pbuf, &addro)) {
- PyErr_Clear();
- if (!PyArg_ParseTuple(args, "s*iO:sendto",
- &pbuf, &flags, &addro))
- return NULL;
+ arglen = PyTuple_Size(args);
+ switch(arglen) {
+ case 2:
+ PyArg_ParseTuple(args, "s*O:sendto", &pbuf, &addro);
+ break;
+ case 3:
+ PyArg_ParseTuple(args, "s*iO:sendto", &pbuf, &flags, &addro);
+ break;
+ default:
+ PyErr_Format(PyExc_TypeError, "sendto() takes 2 or 3"
+ " arguments (%d given)", arglen);
}
+ if (PyErr_Occurred())
+ return NULL;
+
buf = pbuf.buf;
len = pbuf.len;