From e6538aa8fd12fe4fc72bd60b3eb7618bc69bf5d3 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 27 Nov 2016 20:08:48 +0100 Subject: [PATCH] change return value to use -1 on error, as 0 is a legal packet size --- src/gns/gnunet-dns2gns.c | 11 +++++++---- src/include/gnunet_network_lib.h | 2 +- src/util/network.c | 8 ++++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/gns/gnunet-dns2gns.c b/src/gns/gnunet-dns2gns.c index 73d5eab6c..f58303789 100644 --- a/src/gns/gnunet-dns2gns.c +++ b/src/gns/gnunet-dns2gns.c @@ -533,17 +533,20 @@ read_dns4 (void *cls) return; /* read error!? */ } { - char buf[size]; + char buf[size + 1]; addrlen = sizeof (v4); GNUNET_break (size == GNUNET_NETWORK_socket_recvfrom (listen_socket4, buf, - size, + size + 1, (struct sockaddr *) &v4, &addrlen)); - handle_request (listen_socket4, &v4, addrlen, - buf, size); + handle_request (listen_socket4, + &v4, + addrlen, + buf, + size); } } diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h index 8064140aa..beca83807 100644 --- a/src/include/gnunet_network_lib.h +++ b/src/include/gnunet_network_lib.h @@ -244,7 +244,7 @@ GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, * How much data is available to be read on this descriptor? * * @param desc socket - * @returns #GNUNET_NO if no data is available, or on error! + * @returns #GNUNET_SYSERR if no data is available, or on error! */ ssize_t GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle *desc); diff --git a/src/util/network.c b/src/util/network.c index 5aeb0157b..67f2801c5 100644 --- a/src/util/network.c +++ b/src/util/network.c @@ -770,7 +770,7 @@ GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, * How much data is available to be read on this descriptor? * * @param desc socket - * @returns #GNUNET_NO if no data is available, or on error! + * @returns #GNUNET_SYSERR if no data is available, or on error! */ ssize_t GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle *desc) @@ -784,9 +784,9 @@ GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle *desc) error = ioctl (desc->fd, FIONREAD, &pending); - if (error == 0) + if (0 == error) return (ssize_t) pending; - return GNUNET_NO; + return GNUNET_SYSERR; #else u_long pending; @@ -795,7 +795,7 @@ GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle *desc) &pending); if (error != SOCKET_ERROR) return (ssize_t) pending; - return GNUNET_NO; + return GNUNET_SYSERR; #endif } -- 2.25.1