All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: fix gcc8 default build warning caused by '-Wformat-truncation'
@ 2018-10-26  1:58 Su Yanjun
  2018-10-26  5:11 ` Qu Wenruo
  2018-11-16  7:24 ` Qu Wenruo
  0 siblings, 2 replies; 3+ messages in thread
From: Su Yanjun @ 2018-10-26  1:58 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Su Yanjun

When using gcc8 compiles utils.c, it complains as below:

utils.c:852:45: warning: '%s' directive output may be truncated writing
up to 4095 bytes into a region of size 4084 [-Wformat-truncation=]
   snprintf(path, sizeof(path), "/dev/mapper/%s", name);
                                             ^~   ~~~~
In file included from /usr/include/stdio.h:873,
                 from utils.c:20:
/usr/include/bits/stdio2.h:67:10: note: '__builtin___snprintf_chk'
output between 13 and 4108 bytes into a destination of size 4096
   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        __bos (__s), __fmt, __va_arg_pack ());
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This isn't a type of warning we care about, particularly when PATH_MAX
is much less than either.

Using the GCC option -Wno-format-truncation to disable this for default
build.

Signed-off-by: Su Yanjun <suyj.fnst@cn.fujitsu.com>
---
 Makefile.extrawarn | 1 +
 configure.ac       | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/Makefile.extrawarn b/Makefile.extrawarn
index 1f4bda94a167..ed76fb5b5554 100644
--- a/Makefile.extrawarn
+++ b/Makefile.extrawarn
@@ -47,6 +47,7 @@ warning-1 += -Wold-style-definition
 warning-1 += $(call cc-option, -Wmissing-include-dirs)
 warning-1 += $(call cc-option, -Wunused-but-set-variable)
 warning-1 += $(call cc-disable-warning, missing-field-initializers)
+warning-1 += $(call cc-option, -Wformat-truncation)
 
 warning-2 := -Waggregate-return
 warning-2 += -Wcast-align
diff --git a/configure.ac b/configure.ac
index df02f20655d9..c626beca8b77 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,7 +12,7 @@ LIBBTRFS_MAJOR=0
 LIBBTRFS_MINOR=1
 LIBBTRFS_PATCHLEVEL=2
 
-CFLAGS=${CFLAGS:-"-g -O1 -Wall -D_FORTIFY_SOURCE=2"}
+CFLAGS=${CFLAGS:-"-g -O1 -Wall -D_FORTIFY_SOURCE=2 -Wno-format-truncation"}
 AC_SUBST([CFLAGS])
 
 AC_PREREQ([2.60])
-- 
2.19.1




^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs-progs: fix gcc8 default build warning caused by '-Wformat-truncation'
  2018-10-26  1:58 [PATCH] btrfs-progs: fix gcc8 default build warning caused by '-Wformat-truncation' Su Yanjun
@ 2018-10-26  5:11 ` Qu Wenruo
  2018-11-16  7:24 ` Qu Wenruo
  1 sibling, 0 replies; 3+ messages in thread
From: Qu Wenruo @ 2018-10-26  5:11 UTC (permalink / raw)
  To: Su Yanjun, linux-btrfs


[-- Attachment #1.1: Type: text/plain, Size: 2339 bytes --]



On 2018/10/26 上午9:58, Su Yanjun wrote:
> When using gcc8 compiles utils.c, it complains as below:
> 
> utils.c:852:45: warning: '%s' directive output may be truncated writing
> up to 4095 bytes into a region of size 4084 [-Wformat-truncation=]
>    snprintf(path, sizeof(path), "/dev/mapper/%s", name);
>                                              ^~   ~~~~

As long as we're using snprintf(), we expect some string to be
truncated, so it's not a problem at all.

> In file included from /usr/include/stdio.h:873,
>                  from utils.c:20:
> /usr/include/bits/stdio2.h:67:10: note: '__builtin___snprintf_chk'
> output between 13 and 4108 bytes into a destination of size 4096
>    return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
>           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>         __bos (__s), __fmt, __va_arg_pack ());
>         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> This isn't a type of warning we care about, particularly when PATH_MAX
> is much less than either.
> 
> Using the GCC option -Wno-format-truncation to disable this for default
> build.
> 
> Signed-off-by: Su Yanjun <suyj.fnst@cn.fujitsu.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu

> ---
>  Makefile.extrawarn | 1 +
>  configure.ac       | 2 +-
>  2 files changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/Makefile.extrawarn b/Makefile.extrawarn
> index 1f4bda94a167..ed76fb5b5554 100644
> --- a/Makefile.extrawarn
> +++ b/Makefile.extrawarn
> @@ -47,6 +47,7 @@ warning-1 += -Wold-style-definition
>  warning-1 += $(call cc-option, -Wmissing-include-dirs)
>  warning-1 += $(call cc-option, -Wunused-but-set-variable)
>  warning-1 += $(call cc-disable-warning, missing-field-initializers)
> +warning-1 += $(call cc-option, -Wformat-truncation)
>  
>  warning-2 := -Waggregate-return
>  warning-2 += -Wcast-align
> diff --git a/configure.ac b/configure.ac
> index df02f20655d9..c626beca8b77 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -12,7 +12,7 @@ LIBBTRFS_MAJOR=0
>  LIBBTRFS_MINOR=1
>  LIBBTRFS_PATCHLEVEL=2
>  
> -CFLAGS=${CFLAGS:-"-g -O1 -Wall -D_FORTIFY_SOURCE=2"}
> +CFLAGS=${CFLAGS:-"-g -O1 -Wall -D_FORTIFY_SOURCE=2 -Wno-format-truncation"}
>  AC_SUBST([CFLAGS])
>  
>  AC_PREREQ([2.60])
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs-progs: fix gcc8 default build warning caused by '-Wformat-truncation'
  2018-10-26  1:58 [PATCH] btrfs-progs: fix gcc8 default build warning caused by '-Wformat-truncation' Su Yanjun
  2018-10-26  5:11 ` Qu Wenruo
@ 2018-11-16  7:24 ` Qu Wenruo
  1 sibling, 0 replies; 3+ messages in thread
From: Qu Wenruo @ 2018-11-16  7:24 UTC (permalink / raw)
  To: Su Yanjun, linux-btrfs


[-- Attachment #1.1: Type: text/plain, Size: 2388 bytes --]



On 2018/10/26 上午9:58, Su Yanjun wrote:
> When using gcc8 compiles utils.c, it complains as below:
> 
> utils.c:852:45: warning: '%s' directive output may be truncated writing
> up to 4095 bytes into a region of size 4084 [-Wformat-truncation=]
>    snprintf(path, sizeof(path), "/dev/mapper/%s", name);
>                                              ^~   ~~~~
> In file included from /usr/include/stdio.h:873,
>                  from utils.c:20:
> /usr/include/bits/stdio2.h:67:10: note: '__builtin___snprintf_chk'
> output between 13 and 4108 bytes into a destination of size 4096
>    return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
>           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>         __bos (__s), __fmt, __va_arg_pack ());
>         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> This isn't a type of warning we care about, particularly when PATH_MAX
> is much less than either.
> 
> Using the GCC option -Wno-format-truncation to disable this for default
> build.
> 
> Signed-off-by: Su Yanjun <suyj.fnst@cn.fujitsu.com>
> ---
>  Makefile.extrawarn | 1 +
>  configure.ac       | 2 +-
>  2 files changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/Makefile.extrawarn b/Makefile.extrawarn
> index 1f4bda94a167..ed76fb5b5554 100644
> --- a/Makefile.extrawarn
> +++ b/Makefile.extrawarn
> @@ -47,6 +47,7 @@ warning-1 += -Wold-style-definition
>  warning-1 += $(call cc-option, -Wmissing-include-dirs)
>  warning-1 += $(call cc-option, -Wunused-but-set-variable)
>  warning-1 += $(call cc-disable-warning, missing-field-initializers)
> +warning-1 += $(call cc-option, -Wformat-truncation)

Have you tried "make W=1"?

This won't work.
You should use cc-disable-warning, however we forgot to include that
function.

I'll fix it and put your patch into my pile of make W=1 cleanups.

Thanks,
Qu

>  
>  warning-2 := -Waggregate-return
>  warning-2 += -Wcast-align
> diff --git a/configure.ac b/configure.ac
> index df02f20655d9..c626beca8b77 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -12,7 +12,7 @@ LIBBTRFS_MAJOR=0
>  LIBBTRFS_MINOR=1
>  LIBBTRFS_PATCHLEVEL=2
>  
> -CFLAGS=${CFLAGS:-"-g -O1 -Wall -D_FORTIFY_SOURCE=2"}
> +CFLAGS=${CFLAGS:-"-g -O1 -Wall -D_FORTIFY_SOURCE=2 -Wno-format-truncation"}
>  AC_SUBST([CFLAGS])
>  
>  AC_PREREQ([2.60])
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-11-16  7:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-26  1:58 [PATCH] btrfs-progs: fix gcc8 default build warning caused by '-Wformat-truncation' Su Yanjun
2018-10-26  5:11 ` Qu Wenruo
2018-11-16  7:24 ` Qu Wenruo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.