diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-07-26 12:52:55 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-07-26 12:52:55 (GMT) |
commit | 0a649c7bb1bdc6238963decc5b77ad805e551a9e (patch) | |
tree | 1b58230a6f6526cf51f54371bd8153c3dd4882c3 /Modules/socketmodule.c | |
parent | 465db3c69ad69df013149eaecffc3ac719b177ca (diff) | |
download | cpython-0a649c7bb1bdc6238963decc5b77ad805e551a9e.zip cpython-0a649c7bb1bdc6238963decc5b77ad805e551a9e.tar.gz cpython-0a649c7bb1bdc6238963decc5b77ad805e551a9e.tar.bz2 |
Fix repr(_socket.socket) on Windows 64-bit: don't fail with OverflowError
on closed socket.
Diffstat (limited to 'Modules/socketmodule.c')
-rw-r--r-- | Modules/socketmodule.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 130b6b3..0127a6c 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -3123,8 +3123,13 @@ static PyObject * sock_repr(PySocketSockObject *s) { char buf[512]; + long sock_fd; + /* On Windows, this test is needed because SOCKET_T is unsigned */ + if (s->sock_fd == INVALID_SOCKET) { + sock_fd = -1; + } #if SIZEOF_SOCKET_T > SIZEOF_LONG - if (s->sock_fd > LONG_MAX) { + else if (s->sock_fd > LONG_MAX) { /* this can occur on Win64, and actually there is a special ugly printf formatter for decimal pointer length integer printing, only bother if necessary*/ @@ -3134,10 +3139,12 @@ sock_repr(PySocketSockObject *s) return NULL; } #endif + else + sock_fd = (long)s->sock_fd; PyOS_snprintf( buf, sizeof(buf), "<socket object, fd=%ld, family=%d, type=%d, protocol=%d>", - (long)s->sock_fd, s->sock_family, + sock_fd, s->sock_family, s->sock_type, s->sock_proto); return PyString_FromString(buf); |