Re: Fixing "cast truncates bits from constant value"

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

 



On Wed, Aug 19, 2009 at 4:28 PM, Pavel Roskin<proski@xxxxxxx> wrote:
>
> static unsigned short test(void)
> {
>      return (unsigned short)(0xffff & ~0x8000);
> }
>
> I think it's ugly.  And that's what b43 developers think, so the sparce
> warning remains unfixed.


You can use a macro with nice name to do the convert plus AND 0xffff.
e.g.

return short_value(~0x8000);


>
>> > In my opinion, an explicit cast should be enough to suppress the
>> > warning.  But it's not.  Moreover, it's a "superwarning" that cannot
>> > even be suppressed by the "force" attribute!  This source still
>> > generates a warning:
>> >
>> > static unsigned short test(void)
>> > {
>> >        return (__attribute__((force)) unsigned short)~0x8000;
>>
>> Sparse currently does not thing than just mark it as forced.
>
> The whole point of having that attribute is to suppress warnings.

Yes, there is a lot of place sparse is complete yet. If any one want
to send patches. I am glad to review it.

>> > static unsigned short test(void)
>> > {
>> >        return 0xfffff000U;
>> > }
>>
>> I think sparse consider it as signed extend.
>> Truncating all 0xffff is consider OK for the negative case.
>
> That's wrong, as there are no signed integers involved in the above
> example.

True. But sparse is not a validations tool. It just point out the possible
warnings. If a warning has too much false positives. It is pretty much
useless. What you are suggesting will cause too much unnecessary
warnings. I haven't try it myself, but I suspect the kernel using negative
error code in pointers might trigger this.

Chris
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux