[Libguestfs] [PATCH] build: Reduce -Wformat-overflow=2 to =1.
Richard W.M. Jones
rjones at redhat.com
Mon Jan 21 16:43:37 UTC 2019
On Mon, Jan 21, 2019 at 04:02:22PM +0000, Richard W.M. Jones wrote:
> GCC 9 gives this error which I believe is bogus:
It turns out it's not bogus (sort of). C99 says the minimum length of
strings supported by %s has to be at least 4095:
https://stackoverflow.com/questions/8119914/printf-fprintf-maximum-size-according-to-c99?rq=1
Of course that's in some extreme minimal case and I hope it doesn't
apply to our actual glibc printf. It would be nice if the limit could
reflect what glibc can do.
I think turned down or off the warning is still the right thing here,
but the commit message could be better.
Rich.
> qemuopts.c: In function 'qemuopts_to_config_channel':
> qemuopts.c:987:29: error: '%.*s' directive output between 0 and 2147483647 bytes may exceed minimum required size of 4095 [-Werror=format-overflow=]
> 987 | fprintf (fp, " %.*s = ", (int) k, values[j]);
> | ^~~~
> qemuopts.c:987:26: note: assuming directive output of 1 byte
> 987 | fprintf (fp, " %.*s = ", (int) k, values[j]);
> | ^~~~~~~~~~~
> ---
> m4/guestfs-c.m4 | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/m4/guestfs-c.m4 b/m4/guestfs-c.m4
> index 3fd44ed6b..e20721f5f 100644
> --- a/m4/guestfs-c.m4
> +++ b/m4/guestfs-c.m4
> @@ -105,6 +105,9 @@ gl_WARN_ADD([-Wimplicit-fallthrough=4])
> dnl GCC level 2 gives incorrect warnings, so use level 1.
> gl_WARN_ADD([-Wformat-truncation=1])
>
> +dnl GCC 9 at level 2 gives apparently bogus errors when %.*s is used.
> +gl_WARN_ADD([-Wformat-overflow=1])
> +
> AC_SUBST([WARN_CFLAGS])
>
> NO_SNV_CFLAGS=
> --
> 2.20.1
>
> _______________________________________________
> Libguestfs mailing list
> Libguestfs at redhat.com
> https://www.redhat.com/mailman/listinfo/libguestfs
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top
More information about the Libguestfs
mailing list