On Tue, Apr 25, 2023 at 10:52:45AM +1000, David Leonard wrote:
> On Mon, 24 Apr 2023, Harald van Dijk wrote:
> > coreutils/readlink.c:91:27: warning: adding 'unsigned int' to a string
> > does not append to the string [-Wstring-plus-int]
> > printf("%s%s", buf, "\n" + (opt & 1));
> > ~~~~~^~~~~~~~~~~
> > coreutils/readlink.c:91:27: note: use array indexing to silence this warning
> > printf("%s%s", buf, "\n" + (opt & 1));
> > ^
> > & [ ]
> >
> > I am not sure what busybox's intent is here. If busybox decides that
> > this warning is useless, it would be nice if it got suppressed reliably.
>
> Alternatively, avoid warnings with this construction which gives pretty
> good size results:
>
> if (opt)
That's not the same as 'if (opt & 1)'. As such, you are not comparing
apples to oranges...
> fputs(buf, stdout);
> else
> puts(buf);
>
>
>
> The rest of this email is cc/size experiment results.
>
> $ ./cc-size -c f1.c -Os
> cc -c f1.c -Os
> -DT0 -DT1 -DT2 -DT3
> aarch64 1584 -80 -8 +48
> arm 1008 -48 -20 +0
> mips 1396 -72 +8 +64
> x86_64 1520 -80 -32 +0
> gcc 1552 -96 +8 +72
> clang 1280 -80 +0 +72
Still, the numbers for -DT1 are compelling, despite the potential
change for a slight increase in bytes once you use correct logic.
>
> The numbers represent the increase in byte size of f1.o compared to when
> compiled with baseline -DT0.
>
> $ cat f1.c
> #include <stdio.h>
>
> /* suppress trailing newline when opt */
> int f1(int opt, char buf[]) {
> #if defined(T0)
> if (opt) printf("%s", buf); else printf("%s\n", buf);
> #elif defined(T1)
> if (opt) fputs(buf, stdout); else puts(buf);
> #elif defined(T2)
> printf("%s%s", buf, "\n" + (opt & 1));
Of the four tests, T2 is the only one with correct semantics.
> #elif defined(T3)
> printf("%s%s", buf, opt ? "" : "\n");
> #else
> # error "forgot to -DTx"
> #endif
> }
>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox