Re: Fwd: [PATCH] tools/headers: Fix undefined behaviour (34 << 26)

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

 



Hi--

[adding linux-mm mailing list]

On 9/2/22 23:59, Matthias Görgens wrote:
> Hello,
> 
> This is my first patch to the Linux kernel.  I hope sending it via
> gmail is OK?  I have attached the git-generated patch file.
> 
gmail's web UI won't do it AFAIK.
And most people won't accept patches as attachments.
(more difficult to review and reply with comments to them)


The easiest fix for that (IMO) while continuing to use gmail is to
use 'git send-email'.

> This is a simple fix to a problem I encountered when I tried to build
> CPython.  Some digging suggested that the problem is actually with
> kernel header files.
> 
> Basically the problem is that when calculating
> `HUGETLB_FLAG_ENCODE_16GB` we essentially run (34 << 26).  That's
> undefined behaviour in C, because C tries to do these calculations as
> signed ints, but signed signed ints don't have enough bits.
> 
> The fix is to cast to unsigned first: ((unsigned) 32 << 26).  Unsigned
> ints have enough bits, at least on 32 bit systems and above.

Instead of casting to (unsigned), can you use a constant suffix format,
like 34U << 26 ?

> I suspect the way the kernel build uses GCC and Clang this is probably
> not a problem, but the headers are used by outside projects (like
> CPython), and for that it's probably best to stick to the C standard,
> when it's easy to do so.
> 
> Thanks,
> Matthias.
> 
> P.S. Please pardon, if you received this email a second time, I had
> some trouble getting GMail to send in plain text.

-- 
~Randy




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux