[SLOF] [PATCH slof 02/13] libc: Compile with -Wextra

Alexey Kardashevskiy aik at ozlabs.ru
Thu Jan 28 11:09:18 AEDT 2021



On 28/01/2021 09:48, Segher Boessenkool wrote:
> On Wed, Jan 27, 2021 at 01:58:26PM +0100, Thomas Huth wrote:
>> On 27/01/2021 09.57, Alexey Kardashevskiy wrote:
>>> -			(i < (sizei - len)) && ((*buffer - bstart) <
>>> bufsize);
>>> -									i++)
>>> {
>>> +			(i < (sizei - len)) && ((*buffer - bstart) <
>>> (int)bufsize);
>>
>> bufsize is of type size_t, so the correct way to cast would be "(ssize_t)"
>> instead of "(int)", I think.
>> Maybe it would also be worth the effort to introduce a new local variable a
>> la:
>>
>>   ssize_t sbufsize = (ssize_t)bufsize;
>>
>> so that you don't have to do the cast again and again all over the place?
> 
> Or, better:
>    i < (sizei - len) && (size_t)(*buffer - bstart) < bufsize
> 
> If the difference between the two pointers is negative (which it never
> should be, but just assume it is), the cast to an unsigned type will
> make the comparison return false, exactly as we want.

ah this is neat, I did not think about it this way :)



-- 
Alexey


More information about the SLOF mailing list