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

Alexey Kardashevskiy aik at ozlabs.ru
Thu Jan 21 19:59:22 AEDT 2016


On 01/21/2016 07:50 PM, Thomas Huth wrote:
> On 21.01.2016 02:39, 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 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
>
> I think you could also simply do:
>
> 	if (bytes_received < (int)sizeof(struct ethhdr))
> 		return -1;
>
> ... that saves one check and should silence GCC ;-)


imho it is less obvious what is checked when if I do this.


-- 
Alexey


More information about the SLOF mailing list