Re: [PATCH] stat.2: fixed inode printing in example program

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

 



Fair enough, cast is needed. I replied in the main thread with a fixed patch.

Thank you,
Konstantin.

On Sun, Sep 13, 2020 at 11:43 AM Alejandro Colomar
<colomar.6.4.3@xxxxxxxxx> wrote:
>
> > Such erroneous reporting happens for inode values greater than maximum
> > value which can be stored in signed long. Casting does not seem to be
> > necessary here. Printing inode as unsigned long long fixes the issue.
>
> The cast is necessary.
>
> Relevant standard: C18 §6.5.2.2 6
>
> Details: 'ino_t' may (and will likely) be defined as 'unsigned long'.
> If you try to print an 'unsigned long' with "%llu" you will:
> - have Undefined Behavior (and a warning) if 'sizeof(long) < sizeof(long
> long)'.
> - have a warning if 'sizeof(long) == sizeof(long long)'.
>
> So if you want to use 'unsigned long long', you'll need to cast.
>
> Cheers,
>
> Alex




[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux