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

Segher Boessenkool segher at kernel.crashing.org
Thu Jan 28 09:48:41 AEDT 2021


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.


Segher


More information about the SLOF mailing list