[SLOF] [PATCH slof v2 3/4] ethernet: Fix gcc warnings
Alexey Kardashevskiy
aik at ozlabs.ru
Thu Jan 21 12:39:22 AEDT 2016
This fixes gcc warnings but unlike other places, this does not change
the type of bytes_received as recv() may return a negative value;
instead this adds:
1) casting to size_t when comparing the size;
2) an additional check for a negative value returned from recv().
Signed-off-by: Alexey Kardashevskiy <aik at ozlabs.ru>
---
clients/net-snk/app/netlib/ethernet.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/clients/net-snk/app/netlib/ethernet.c b/clients/net-snk/app/netlib/ethernet.c
index b73239e..6ff7355 100644
--- a/clients/net-snk/app/netlib/ethernet.c
+++ b/clients/net-snk/app/netlib/ethernet.c
@@ -117,7 +117,10 @@ int32_t receive_ether(int fd)
if (!bytes_received) // No messages
return 0;
- if (bytes_received < sizeof(struct ethhdr))
+ if (bytes_received < 0)
+ return -1; /* recv() failed */
+
+ if ((size_t) bytes_received < sizeof(struct ethhdr))
return -1; // packet is too small
ethh = (struct ethhdr *) ether_packet;
--
2.5.0.rc3
More information about the SLOF
mailing list