Re: Compiling kernel with -Wformat-signedness gcc flag

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Jeff,

On Fri, Mar 9, 2018 at 2:24 PM, Jeffrey Walton <noloader@xxxxxxxxx> wrote:
> On Fri, Mar 9, 2018 at 8:16 AM, Himanshu Jha
> <himanshujha199640@xxxxxxxxx> wrote:
>> Hello everyone,
>>
>>
>> I just compiled the kernel by passing "-Wformat-signedness" flag
>>
>> https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
>>
>> -Wformat-signedness:
>> If -Wformat is specified, also warn if the format string requires an
>> unsigned argument and the argument is signed and vice versa.
>>
>> Now, the C standard says:
>>
>> "If a conversion specification is invalid, the behavior is undefined.
>> If any argument is
>> not the correct type for the corresponding conversion specification, the
>> behavior is *undefined*."
>>
>> For eg:
>>
>> drivers/iio/trigger/stm32-timer-trigger.c:228:24: warning: format ‘%d’
>> expects argument of type ‘int’, but argument 3 has type ‘unsigned int’
>> [-Wformat=]
>>   return sprintf(buf, "%d\n", (unsigned int)freq);
>>                          ~^     ~~~~~~~~~~~~~~~~~~
>>                                                 %d
>>
>> What is the rationale for not including/using this flag in the
>> HOSTCFLAGS in the Makefile ?
>
> In the past, it was posited the toolchain should be smart enough to
> know when the programmer intended/needed a signed value versus an
> unsigned one. Also see
> http://linux.derkeiler.com/Mailing-Lists/Kernel/2006-11/msg08325.html.

I am not sure this is best example why this flag is not used anymore.
I can see that type-limits is being used. It is even a
-Werror=type-limits when compiling with W=1.

Anyway I see your point, just that the example may be a bit out dated.
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux