[patch] Use unsigned constants for ICMP6 filters [BZ #22489]

Florian Weimer fw@deneb.enyo.de
Sun Apr 26 11:56:46 GMT 2020


* Alexander Monakov via Libc-alpha:

> Computing 1<<31 causes undefined behavior (signed overflow), you get
> a warning with -Wshift-overflow=2 and a runtime error with UBSan,
> i.e. with -fsanitize=undefined.
>
> I'd say the situation with -Wsign-conversion warning is more subtle
> than your initial mail seemed to imply, normally gcc suppresses warnings
> for code originating in system headers unless -Wsystem-headers is also
> specified. Here the warning appears where user code expands a macro
> defined in a system header, maybe this situation is not properly
> handled for -Wsign-conversion in GCC.
>
> In summary, you need 1u to avoid causing undefined behavior if
> a shift left by 31 is possible in practice, and it also happens to
> suppress GCC's -Wsign-conversion warning (while there's
> nothing undefined about the conversion itself).

I believe not of the bits in the array have index 31 at present, so
the undefined behavior cannot really occur in practice at this point.
Perhaps it makes sense to mention both aspects in the commit message,
though.


More information about the Libc-alpha mailing list