Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1a62a68

Browse files
committed
Issue #22218: Fix "comparison between signed and unsigned integers" warnings in
socketmodule.c.
1 parent c399e85 commit 1a62a68

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

Modules/socketmodule.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,7 @@ idna_converter(PyObject *obj, struct maybe_idna *data)
12771277
return 0;
12781278
}
12791279
return Py_CLEANUP_SUPPORTED;
1280-
}
1280+
}
12811281

12821282
/* Parse a socket address argument according to the socket object's
12831283
address family. Return 1 if the address was in the proper format,
@@ -1308,12 +1308,13 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
13081308
Py_INCREF(args);
13091309
if (!PyArg_Parse(args, "y#", &path, &len))
13101310
goto unix_out;
1311+
assert(len >= 0);
13111312

13121313
addr = (struct sockaddr_un*)addr_ret;
13131314
#ifdef linux
13141315
if (len > 0 && path[0] == 0) {
13151316
/* Linux abstract namespace extension */
1316-
if (len > sizeof addr->sun_path) {
1317+
if ((size_t)len > sizeof addr->sun_path) {
13171318
PyErr_SetString(PyExc_OSError,
13181319
"AF_UNIX path too long");
13191320
goto unix_out;
@@ -1323,7 +1324,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
13231324
#endif /* linux */
13241325
{
13251326
/* regular NULL-terminated string */
1326-
if (len >= sizeof addr->sun_path) {
1327+
if ((size_t)len >= sizeof addr->sun_path) {
13271328
PyErr_SetString(PyExc_OSError,
13281329
"AF_UNIX path too long");
13291330
goto unix_out;
@@ -1675,7 +1676,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
16751676

16761677
if (len == 0) {
16771678
ifr.ifr_ifindex = 0;
1678-
} else if (len < sizeof(ifr.ifr_name)) {
1679+
} else if ((size_t)len < sizeof(ifr.ifr_name)) {
16791680
strncpy(ifr.ifr_name, PyBytes_AS_STRING(interfaceName), sizeof(ifr.ifr_name));
16801681
ifr.ifr_name[(sizeof(ifr.ifr_name))-1] = '\0';
16811682
if (ioctl(s->sock_fd, SIOCGIFINDEX, &ifr) < 0) {
@@ -4290,7 +4291,7 @@ Return the IP address (a string of the form '255.255.255.255') for a host.");
42904291
/* Convenience function common to gethostbyname_ex and gethostbyaddr */
42914292

42924293
static PyObject *
4293-
gethost_common(struct hostent *h, struct sockaddr *addr, int alen, int af)
4294+
gethost_common(struct hostent *h, struct sockaddr *addr, size_t alen, int af)
42944295
{
42954296
char **pch;
42964297
PyObject *rtn_tuple = (PyObject *)NULL;

0 commit comments

Comments
 (0)