[Python-checkins] cpython: Issue #22218: Fix "comparison between signed and unsigned integers" warnings in

victor.stinner python-checkins at python.org
Sun Aug 17 19:34:44 CEST 2014


http://hg.python.org/cpython/rev/05e8f92b58ff
changeset:   92138:05e8f92b58ff
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Sun Aug 17 19:33:28 2014 +0200
summary:
  Issue #22218: Fix "comparison between signed and unsigned integers" warnings in
socketmodule.c.

files:
  Modules/socketmodule.c |  11 ++++++-----
  1 files changed, 6 insertions(+), 5 deletions(-)


diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -1277,7 +1277,7 @@
         return 0;
     }
     return Py_CLEANUP_SUPPORTED;
-}       
+}
 
 /* Parse a socket address argument according to the socket object's
    address family.  Return 1 if the address was in the proper format,
@@ -1308,12 +1308,13 @@
             Py_INCREF(args);
         if (!PyArg_Parse(args, "y#", &path, &len))
             goto unix_out;
+        assert(len >= 0);
 
         addr = (struct sockaddr_un*)addr_ret;
 #ifdef linux
         if (len > 0 && path[0] == 0) {
             /* Linux abstract namespace extension */
-            if (len > sizeof addr->sun_path) {
+            if ((size_t)len > sizeof addr->sun_path) {
                 PyErr_SetString(PyExc_OSError,
                                 "AF_UNIX path too long");
                 goto unix_out;
@@ -1323,7 +1324,7 @@
 #endif /* linux */
         {
             /* regular NULL-terminated string */
-            if (len >= sizeof addr->sun_path) {
+            if ((size_t)len >= sizeof addr->sun_path) {
                 PyErr_SetString(PyExc_OSError,
                                 "AF_UNIX path too long");
                 goto unix_out;
@@ -1675,7 +1676,7 @@
 
             if (len == 0) {
                 ifr.ifr_ifindex = 0;
-            } else if (len < sizeof(ifr.ifr_name)) {
+            } else if ((size_t)len < sizeof(ifr.ifr_name)) {
                 strncpy(ifr.ifr_name, PyBytes_AS_STRING(interfaceName), sizeof(ifr.ifr_name));
                 ifr.ifr_name[(sizeof(ifr.ifr_name))-1] = '\0';
                 if (ioctl(s->sock_fd, SIOCGIFINDEX, &ifr) < 0) {
@@ -4290,7 +4291,7 @@
 /* Convenience function common to gethostbyname_ex and gethostbyaddr */
 
 static PyObject *
-gethost_common(struct hostent *h, struct sockaddr *addr, int alen, int af)
+gethost_common(struct hostent *h, struct sockaddr *addr, size_t alen, int af)
 {
     char **pch;
     PyObject *rtn_tuple = (PyObject *)NULL;

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list