Skip to contentSkip to conversation

ss: fix the compiler warning

PATCH In review Denis Kirjanov 4 participants 4 messages Mar 7, 2024 – Mar 11, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ss: fix the compiler warning

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")
---
 misc/ss.c | 1 +
 1 file changed, 1 insertion(+)
misc/ss.c +1 -0
index 87008d7c..038905f3 100644
@@ -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;
Signature · 1 line
2.30.2
#1 lore raw
Quoted 19 lines · Denis Kirjanov

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")
---
 misc/ss.c | 1 +
 1 file changed, 1 insertion(+)
misc/ss.c +0 -0
index 87008d7c..038905f3 100644

misc/ss.c static int buf_update(int len) · line 1048

Quoted 7 lines
misc/ss.c +1 -0
@@ -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

#2 lore raw
Quoted 22 lines · On Sat, 9 Mar 2024 11:22:34 -0700 David Ahern <[email protected]> wrote:
Quoted 21 lines · Denis Kirjanov

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")
---
 misc/ss.c | 1 +
 1 file changed, 1 insertion(+)
misc/ss.c +0 -0
index 87008d7c..038905f3 100644
@@ -1042,6 +1042,7 @@ static int buf_update(int len)
 }
 
Quoted 8 lines

misc/ss.c static int buf_update(int len) · line 1048

Quoted 5 lines
misc/ss.c +1 -0
 /* 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()

#3 lore raw
In reply to David Ahern
Quoted 22 lines · David Ahern
Quoted 21 lines · Denis Kirjanov

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")
---
 misc/ss.c | 1 +
 1 file changed, 1 insertion(+)
misc/ss.c +0 -0
index 87008d7c..038905f3 100644
@@ -1042,6 +1042,7 @@ static int buf_update(int len)
 }
 
Quoted 8 lines

misc/ss.c static int buf_update(int len) · line 1048

Quoted 5 lines
misc/ss.c +1 -0
 /* 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

Quoted 3 lines

pw-bot: cr