diff mbox series

[iproute2-next] ss: fix the compiler warning

Message ID 20240307105327.2559-1-dkirjanov@suse.de (mailing list archive)
State Changes Requested
Delegated to: David Ahern
Headers show
Series [iproute2-next] ss: fix the compiler warning | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Denis Kirjanov March 7, 2024, 10:53 a.m. UTC
the patch fixes the following compiler warning:

ss.c:1064:53: warning: format string is not a string literal [-Wformat-nonliteral]
        len = vsnprintf(pos, buf_chunk_avail(buffer.tail), fmt, _args);
                                                           ^~~
1 warning generated.
    LINK     ss

Fixes: e3ecf0485 ("ss: pretty-print BPF socket-local storage")
Signed-off-by: Denis Kirjanov <dkirjanov@suse.de>
---
 misc/ss.c | 1 +
 1 file changed, 1 insertion(+)

Comments

David Ahern March 9, 2024, 6:22 p.m. UTC | #1
On 3/7/24 3:53 AM, Denis Kirjanov wrote:
> the patch fixes the following compiler warning:
> 
> ss.c:1064:53: warning: format string is not a string literal [-Wformat-nonliteral]
>         len = vsnprintf(pos, buf_chunk_avail(buffer.tail), fmt, _args);
>                                                            ^~~
> 1 warning generated.
>     LINK     ss
> 
> Fixes: e3ecf0485 ("ss: pretty-print BPF socket-local storage")
> Signed-off-by: Denis Kirjanov <dkirjanov@suse.de>
> ---
>  misc/ss.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/misc/ss.c b/misc/ss.c
> index 87008d7c..038905f3 100644
> --- a/misc/ss.c
> +++ b/misc/ss.c
> @@ -1042,6 +1042,7 @@ static int buf_update(int len)
>  }
>  
>  /* Append content to buffer as part of the current field */
> +__attribute__((format(printf, 1, 0)))
>  static void vout(const char *fmt, va_list args)
>  {
>  	struct column *f = current_field;

The error message does not align with the change - and it does not fix
the warning.

pw-bot: cr
Stephen Hemminger March 9, 2024, 7:30 p.m. UTC | #2
On Sat, 9 Mar 2024 11:22:34 -0700
David Ahern <dsahern@kernel.org> wrote:

> On 3/7/24 3:53 AM, Denis Kirjanov wrote:
> > the patch fixes the following compiler warning:
> > 
> > ss.c:1064:53: warning: format string is not a string literal [-Wformat-nonliteral]
> >         len = vsnprintf(pos, buf_chunk_avail(buffer.tail), fmt, _args);
> >                                                            ^~~
> > 1 warning generated.
> >     LINK     ss
> > 
> > Fixes: e3ecf0485 ("ss: pretty-print BPF socket-local storage")
> > Signed-off-by: Denis Kirjanov <dkirjanov@suse.de>
> > ---
> >  misc/ss.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/misc/ss.c b/misc/ss.c
> > index 87008d7c..038905f3 100644
> > --- a/misc/ss.c
> > +++ b/misc/ss.c
> > @@ -1042,6 +1042,7 @@ static int buf_update(int len)
> >  }
> >  
> >  /* Append content to buffer as part of the current field */
> > +__attribute__((format(printf, 1, 0)))
> >  static void vout(const char *fmt, va_list args)
> >  {
> >  	struct column *f = current_field;  
> 
> The error message does not align with the change - and it does not fix
> the warning.

Think you need to add attribute to out_bpf_sk_storage_print_fn as well,
or better yet get rid of it since it could just be vout()
Denis Kirjanov March 11, 2024, 2:20 p.m. UTC | #3
On 3/9/24 21:22, David Ahern wrote:
> On 3/7/24 3:53 AM, Denis Kirjanov wrote:
>> the patch fixes the following compiler warning:
>>
>> ss.c:1064:53: warning: format string is not a string literal [-Wformat-nonliteral]
>>         len = vsnprintf(pos, buf_chunk_avail(buffer.tail), fmt, _args);
>>                                                            ^~~
>> 1 warning generated.
>>     LINK     ss
>>
>> Fixes: e3ecf0485 ("ss: pretty-print BPF socket-local storage")
>> Signed-off-by: Denis Kirjanov <dkirjanov@suse.de>
>> ---
>>  misc/ss.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/misc/ss.c b/misc/ss.c
>> index 87008d7c..038905f3 100644
>> --- a/misc/ss.c
>> +++ b/misc/ss.c
>> @@ -1042,6 +1042,7 @@ static int buf_update(int len)
>>  }
>>  
>>  /* Append content to buffer as part of the current field */
>> +__attribute__((format(printf, 1, 0)))
>>  static void vout(const char *fmt, va_list args)
>>  {
>>  	struct column *f = current_field;
> 
> The error message does not align with the change - and it does not fix
> the warning.

since vout is not a variadic arguments function I put 0 into the 3rd argument since we 
already have a check in out function.
doc[0] states that:
"For functions where the arguments are not available to be checked (such as vprintf),
specify the third parameter as zero. 
In this case the compiler only checks the format string for consistency." 

[0]: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html
> 
> pw-bot: cr
>
diff mbox series

Patch

diff --git a/misc/ss.c b/misc/ss.c
index 87008d7c..038905f3 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -1042,6 +1042,7 @@  static int buf_update(int len)
 }
 
 /* Append content to buffer as part of the current field */
+__attribute__((format(printf, 1, 0)))
 static void vout(const char *fmt, va_list args)
 {
 	struct column *f = current_field;