From 614096940a0cb2a7f6199944bbe8256701d79cf4 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 10 Feb 2016 13:11:28 +0000 Subject: [PATCH 4/7] Consistently use socklen_t for getsockname, getsockopt etc. This fixes signedness mismatch warnings on platforms where socklen_t is unsigned, notably Linux (where it's an unsigned int). We still use int for the fallback case where the platform does not define socklen_t, because that was the traditional (pre-POSIX) type: for details see NOTES in Linux accept(2), . Bug: https://bugs.freedesktop.org/show_bug.cgi?id=93069 Signed-off-by: Simon McVittie --- dbus/dbus-sysdeps-unix.c | 4 ++-- tools/dbus-print-message.c | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 476cf0d..a963412 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -1905,7 +1905,7 @@ _dbus_read_credentials_socket (DBusSocket client_fd, #else struct ucred cr; #endif - int cr_len = sizeof (cr); + socklen_t cr_len = sizeof (cr); if (getsockopt (client_fd.fd, SOL_SOCKET, SO_PEERCRED, &cr, &cr_len) != 0) { @@ -4365,7 +4365,7 @@ _dbus_append_address_from_socket (DBusSocket fd, struct sockaddr_in6 ipv6; } socket; char hostip[INET6_ADDRSTRLEN]; - int size = sizeof (socket); + socklen_t size = sizeof (socket); DBusString path_str; if (getsockname (fd.fd, &socket.sa, &size)) diff --git a/tools/dbus-print-message.c b/tools/dbus-print-message.c index b747e87..547f72f 100644 --- a/tools/dbus-print-message.c +++ b/tools/dbus-print-message.c @@ -52,6 +52,10 @@ #endif #endif +#ifndef HAVE_SOCKLEN_T +#define socklen_t int +#endif + static const char* type_to_name (int message_type) { @@ -182,8 +186,8 @@ print_fd (int fd, int depth) struct sockaddr_in6 ipv6; } addr, peer; char hostip[INET6_ADDRSTRLEN]; - int addrlen = sizeof (addr); - int peerlen = sizeof (peer); + socklen_t addrlen = sizeof (addr); + socklen_t peerlen = sizeof (peer); int has_peer; /* Don't print the fd number: it is different in every process and since -- 2.7.0