Messages in this thread |  | | From | David Laight <> | Subject | RE: [PATCH] include/uapi/linux/swab.h: add __u16 cast to __swab16 conditional | Date | Fri, 10 Jun 2022 07:19:38 +0000 |
| |
From: Nick Desaulniers > Sent: 08 June 2022 20:35 .... > The issue we're facing is more so that `ntohs` is being used in > printf-like expressions; clang's -Wformat warns about default argument > promotion so we need to clean up cases where smaller-than-int format > flags are being used for promoted-to-int params. While looking at > that, Nathan noticed that __swab16 will return either a __u16 or an > int based on whether __HAVE_BUILTIN_BSWAP16__ is defined, which > depends on BOTH the compiler being used and target architecture. This > patch from Justin just cleans that up.
The 'problem' is that the (__u16) cast is likely to add an extra '& 0xffff' instruction that is almost certainly not required.
OTOH the lack of this masking has always been a difference between htons() on BE and LE systems.
But clang is also being over-enthusiastic with its warnings. IIRC varargs parameters always get integer promotion. So if %hd ever makes sense for printf then it implies a mask inside printf.
David
- Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
|  |