[glib: 7/8] Fix signedness warning in gio/gsocket.c




commit db5a9d83976e2dfca9667ed4c6001b4e3b84334f
Author: Emmanuel Fleury <emmanuel fleury gmail com>
Date:   Fri May 14 14:04:16 2021 +0200

    Fix signedness warning in gio/gsocket.c
    
    gio/gsocket.c: In function 'g_socket_get_available_bytes':
    gio/gsocket.c:3141:17: warning: comparison of integer expressions of different signedness: 'u_long' {aka 
'long unsigned int'} and 'int'
           if (avail == -1)
                     ^~
    gio/gsocket.c: In function 'g_socket_send_messages_with_timeout':
    gio/gsocket.c:5283:19: warning: comparison of integer expressions of different signedness: 'gint' {aka 
'int'} and 'guint' {aka 'unsigned int'}
         for (i = 0; i < num_messages; ++i)
                       ^
    gio/gsocket.c:5308:76: warning: operand of ?: changes signedness from 'int' to 'gsize' {aka 'long long 
unsigned int'} due to unsignedness of other operand
             result = pollable_result == G_POLLABLE_RETURN_OK ? bytes_written : -1;
                                                                                ^~

 gio/gsocket.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/gio/gsocket.c b/gio/gsocket.c
index d13e2cab7..43eb98692 100644
--- a/gio/gsocket.c
+++ b/gio/gsocket.c
@@ -3138,7 +3138,7 @@ g_socket_get_available_bytes (GSocket *socket)
        * systems add internal header size to the reported size, making it
        * unusable for this function. */
       avail = recv (socket->priv->fd, buf, bufsize, MSG_PEEK);
-      if (avail == -1)
+      if ((gint) avail == -1)
         {
           int errsv = get_socket_errno ();
 #ifdef G_OS_WIN32
@@ -5275,7 +5275,7 @@ g_socket_send_messages_with_timeout (GSocket        *socket,
 #else
   {
     gssize result;
-    gint i;
+    guint i;
     gint64 wait_timeout;
 
     wait_timeout = timeout_us;
@@ -5305,7 +5305,11 @@ g_socket_send_messages_with_timeout (GSocket        *socket,
 #endif
           }
 
-        result = pollable_result == G_POLLABLE_RETURN_OK ? bytes_written : -1;
+        if (G_MAXSSIZE > bytes_written &&
+            pollable_result == G_POLLABLE_RETURN_OK)
+          result = (gssize) bytes_written;
+        else
+          result = -1;
 
         /* check if we've timed out or how much time to wait at most */
         if (timeout_us > 0)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]