ioctl: overflow in implicit constant conversion
I’m compiling with
-Wall on 3.6 and get
overflow in implicit constant conversion compiler warnings on some
ioctl() calls in my code.
Upon investigation, I found
int ioctl (int, int, ...)
/usr/include/sys/ioctl.h and the following in
/usr/include/bits/ioctl.h (included by the former)
#define _IOC(a,b,c,d) ( ((a)<<30) | ((b)<<8) | (c) | ((d)<<16) ) #define _IOC_NONE 0U #define _IOC_WRITE 1U #define _IOC_READ 2U #define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0) #define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c)) #define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c)) #define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c))
If I am not mistaken and assuming a 32-bit
int, that means that any
second argument passed to
ioctl() that is created using the
_IOWR macros will be an unsigned 32-bit integer with its most
significant bit set and will trigger the warning I observe.
I subscribe to AWARE (All Warnings Are Really Errors) and normally also
-Werror so I really would like to get this fixed.
BTW, most other distributions I compile on define
int ioctl (int, unsigned long, ...)
and chaging your declaration to take an
unsigned int “fixes” this for
(from redmine: issue id 7580, created on 2017-07-21)