summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorErlend Egeberg Aasland <erlend.aasland@innova.no>2020-12-31 13:16:50 (GMT)
committerGitHub <noreply@github.com>2020-12-31 13:16:50 (GMT)
commitf4936ad1c4d0ae1948e428aeddc7d3096252dae4 (patch)
tree41b6303976816e01eb30c05420d50236570789c7 /Modules
parent9655434cca5dfbea97bf6d355aec028e840b289c (diff)
downloadcpython-f4936ad1c4d0ae1948e428aeddc7d3096252dae4.zip
cpython-f4936ad1c4d0ae1948e428aeddc7d3096252dae4.tar.gz
cpython-f4936ad1c4d0ae1948e428aeddc7d3096252dae4.tar.bz2
bpo-42393: Raise OverflowError iso. DeprecationWarning on overflow in socket.ntohs and socket.htons (GH-23980)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/socketmodule.c36
1 files changed, 10 insertions, 26 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index bb33db0..c686286 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -6102,13 +6102,10 @@ socket_ntohs(PyObject *self, PyObject *args)
return NULL;
}
if (x > 0xffff) {
- if (PyErr_WarnEx(PyExc_DeprecationWarning,
- "ntohs: Python int too large to convert to C "
- "16-bit unsigned integer (The silent truncation "
- "is deprecated)",
- 1)) {
- return NULL;
- }
+ PyErr_SetString(PyExc_OverflowError,
+ "ntohs: Python int too large to convert to C "
+ "16-bit unsigned integer");
+ return NULL;
}
return PyLong_FromUnsignedLong(ntohs((unsigned short)x));
}
@@ -6116,12 +6113,7 @@ socket_ntohs(PyObject *self, PyObject *args)
PyDoc_STRVAR(ntohs_doc,
"ntohs(integer) -> integer\n\
\n\
-Convert a 16-bit unsigned integer from network to host byte order.\n\
-Note that in case the received integer does not fit in 16-bit unsigned\n\
-integer, but does fit in a positive C int, it is silently truncated to\n\
-16-bit unsigned integer.\n\
-However, this silent truncation feature is deprecated, and will raise an\n\
-exception in future versions of Python.");
+Convert a 16-bit unsigned integer from network to host byte order.");
static PyObject *
@@ -6173,13 +6165,10 @@ socket_htons(PyObject *self, PyObject *args)
return NULL;
}
if (x > 0xffff) {
- if (PyErr_WarnEx(PyExc_DeprecationWarning,
- "htons: Python int too large to convert to C "
- "16-bit unsigned integer (The silent truncation "
- "is deprecated)",
- 1)) {
- return NULL;
- }
+ PyErr_SetString(PyExc_OverflowError,
+ "htons: Python int too large to convert to C "
+ "16-bit unsigned integer");
+ return NULL;
}
return PyLong_FromUnsignedLong(htons((unsigned short)x));
}
@@ -6187,12 +6176,7 @@ socket_htons(PyObject *self, PyObject *args)
PyDoc_STRVAR(htons_doc,
"htons(integer) -> integer\n\
\n\
-Convert a 16-bit unsigned integer from host to network byte order.\n\
-Note that in case the received integer does not fit in 16-bit unsigned\n\
-integer, but does fit in a positive C int, it is silently truncated to\n\
-16-bit unsigned integer.\n\
-However, this silent truncation feature is deprecated, and will raise an\n\
-exception in future versions of Python.");
+Convert a 16-bit unsigned integer from host to network byte order.");
static PyObject *