[SLOF] [PATCH slof v3 3/4] ethernet: Fix gcc warnings

Thomas Huth thuth at redhat.com
Wed Jan 27 23:12:43 AEDT 2016


On 22.01.2016 02:03, Alexey Kardashevskiy wrote:
> 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 c24d64f..1e03a0b 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;

Reviewed-by: Thomas Huth <thuth at redhat.com>



More information about the SLOF mailing list