Source-Changes-D archive

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

Re: CVS commit: src/usr.bin/stat



On Fri, May 16, 2025 at 02:32:19AM +0700, Robert Elz wrote:
>     Date:        Thu, 15 May 2025 19:11:44 +0000
>     From:        "Nia Alarie" <nia%netbsd.org@localhost>
>     Message-ID:  <20250515191144.954C6FBE3%cvs.NetBSD.org@localhost>
> 
>   | stat(1): Eliminate a compiler warning
> 
> What was the warning?

stat.c:357:27: error: adding 'int' to a string does not append to the string [-Werror,-Wstring-plus-int]
                                            argv[0], "lstat" + usestat);
                                                     ~~~~~~~~^~~~~~~~~
stat.c:357:27: note: use array indexing to silence this warning
                                            argv[0], "lstat" + usestat);

>   | This code at the moment is a bit magical, as it uses pointer arithemtic
>   | on a string and boolean type to return either "lstat" or "stat".
> 
> No it didn't, it used pointer arith on a string and an int, which is
> perfectly well defined.  That the int was (effectively) true/false
> (ie: 1 or 0) is irrelevant, it is still an int.

I wasn't insinuating it's undefined behaviour, just obfuscating.
As you pointed out the variable is an int, and you have to read
the surrounding code to figure out what it's trying to do,
which is unnecessary.


Home | Main Index | Thread Index | Old Index