[PATCH] linux: Fix integer overflow warnings when including <sys/mount.h> [BZ #32708]

Carlos O'Donell carlos@redhat.com
Tue Mar 25 19:21:30 GMT 2025


On 3/25/25 2:23 PM, Collin Funk wrote:
> Florian Weimer <fweimer@redhat.com> writes:
> 
>> This change alters the type of all enum constants from int to unsigned
>> int.  Should we keep the type of the other constants?  Or use INT_MIN
>> (expanded) for MS_NOUSER?
> 
> Since mount(2) expects an unsigned long flags, I feel like changing it
> to unsigned should be fine. Since the flags are meant to be OR'd
> together, I don't think anyone should be using operators like ==, which
> might trigger -Wsign-compare or something like that.

Agreed.

When I reviewed the patch I considered what the impact of the change to
unsigned might have, but I couldn't come up with a real scenario where
it might matter (other than perhaps recording the type in DWARF data
and checking that). I thought about type promotion, and casting, and
other things, but in this context not much matters.

I also considered if the constant should have been 1UL, but it doesn't
make a difference really. In some static scanners and by MISRA C the
"essential type" of 1U is unsigned char and so coverity might complain
for a shift beyond 8. But we're not trying to comply with MISRA C or
coverity here (we'd have a lot to change if we did).
  
> Let me know if you disagree.

Do we have a concrete scenario where it matters?

-- 
Cheers,
Carlos.



More information about the Libc-alpha mailing list