diff mbox series

[2/9] btrfs-progs: fix gcc8 default build warning caused by '-Wformat-truncation'

Message ID 20181116075426.4142-3-wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: Make W=1 clean (no "again") | expand

Commit Message

Qu Wenruo Nov. 16, 2018, 7:54 a.m. UTC
From: Su Yanjun <suyj.fnst@cn.fujitsu.com>

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>
[Use cc-disable-warning to fix the not working CFLAGS setting in configure.ac]
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 Makefile           | 1 +
 Makefile.extrawarn | 1 +
 2 files changed, 2 insertions(+)

Comments

David Sterba Dec. 4, 2018, 11:10 a.m. UTC | #1
On Fri, Nov 16, 2018 at 03:54:19PM +0800, Qu Wenruo wrote:
> From: Su Yanjun <suyj.fnst@cn.fujitsu.com>
> 
> 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>
> [Use cc-disable-warning to fix the not working CFLAGS setting in configure.ac]
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
>  Makefile           | 1 +
>  Makefile.extrawarn | 1 +
>  2 files changed, 2 insertions(+)
> 
> diff --git a/Makefile b/Makefile
> index f4ab14ea74c8..252299f8869f 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -49,6 +49,7 @@ CSCOPE_CMD := cscope -u -b -c -q
>  include Makefile.extrawarn
>  
>  EXTRA_CFLAGS :=
> +EXTRA_CFLAGS += $(call cc-disable-warning, format-truncation)

Please don't touch EXTRA_CFLAGS, this is for users who want to override
any defaults that are set by build. This should go to CFLAGS.

>  EXTRA_LDFLAGS :=
>  
>  DEBUG_CFLAGS_DEFAULT = -O0 -U_FORTIFY_SOURCE -ggdb3
> diff --git a/Makefile.extrawarn b/Makefile.extrawarn
> index 5849036fd166..bbb2d5173846 100644
> --- a/Makefile.extrawarn
> +++ b/Makefile.extrawarn
> @@ -53,6 +53,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-disable-warning, format-truncation)

It's ok to disable for W=1 but eg. the W=3 level could take all
previously disabled warnings.

>  
>  warning-2 := -Waggregate-return
>  warning-2 += -Wcast-align
> -- 
> 2.19.1
Qu Wenruo Dec. 4, 2018, 12:21 p.m. UTC | #2
On 2018/12/4 下午7:10, David Sterba wrote:
> On Fri, Nov 16, 2018 at 03:54:19PM +0800, Qu Wenruo wrote:
>> From: Su Yanjun <suyj.fnst@cn.fujitsu.com>
>>
>> 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>
>> [Use cc-disable-warning to fix the not working CFLAGS setting in configure.ac]
>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>> ---
>>  Makefile           | 1 +
>>  Makefile.extrawarn | 1 +
>>  2 files changed, 2 insertions(+)
>>
>> diff --git a/Makefile b/Makefile
>> index f4ab14ea74c8..252299f8869f 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -49,6 +49,7 @@ CSCOPE_CMD := cscope -u -b -c -q
>>  include Makefile.extrawarn
>>  
>>  EXTRA_CFLAGS :=
>> +EXTRA_CFLAGS += $(call cc-disable-warning, format-truncation)
> 
> Please don't touch EXTRA_CFLAGS, this is for users who want to override
> any defaults that are set by build. This should go to CFLAGS.
> 
>>  EXTRA_LDFLAGS :=
>>  
>>  DEBUG_CFLAGS_DEFAULT = -O0 -U_FORTIFY_SOURCE -ggdb3
>> diff --git a/Makefile.extrawarn b/Makefile.extrawarn
>> index 5849036fd166..bbb2d5173846 100644
>> --- a/Makefile.extrawarn
>> +++ b/Makefile.extrawarn
>> @@ -53,6 +53,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-disable-warning, format-truncation)
> 
> It's ok to disable for W=1 but eg. the W=3 level could take all
> previously disabled warnings.

Any guide on the warning disabling?

IMHO the format-truncation used in any snprintf()-like functions are
really more or less expected, just like missing-field-initializers.

THanks,
Qu

> 
>>  
>>  warning-2 := -Waggregate-return
>>  warning-2 += -Wcast-align
>> -- 
>> 2.19.1
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index f4ab14ea74c8..252299f8869f 100644
--- a/Makefile
+++ b/Makefile
@@ -49,6 +49,7 @@  CSCOPE_CMD := cscope -u -b -c -q
 include Makefile.extrawarn
 
 EXTRA_CFLAGS :=
+EXTRA_CFLAGS += $(call cc-disable-warning, format-truncation)
 EXTRA_LDFLAGS :=
 
 DEBUG_CFLAGS_DEFAULT = -O0 -U_FORTIFY_SOURCE -ggdb3
diff --git a/Makefile.extrawarn b/Makefile.extrawarn
index 5849036fd166..bbb2d5173846 100644
--- a/Makefile.extrawarn
+++ b/Makefile.extrawarn
@@ -53,6 +53,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-disable-warning, format-truncation)
 
 warning-2 := -Waggregate-return
 warning-2 += -Wcast-align