diff mbox series

[OpenWrt-Devel] firewall: Fix Wformat-nonliteral warning

Message ID 20191129210634.4066-1-rosenp@gmail.com
State Changes Requested
Delegated to: Petr Štetiar
Headers show
Series [OpenWrt-Devel] firewall: Fix Wformat-nonliteral warning | expand

Commit Message

Rosen Penev Nov. 29, 2019, 9:06 p.m. UTC
Allows GCC to check the formats by switching to a define, which is a
constant expression.

Fixes:

warning: format not a string literal, argument types not checked
[-Wformat-nonliteral]
  207 |  snprintf(buf, sizeof(buf), tmpl, include->path);

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 includes.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Jonas Gorski Dec. 1, 2019, 1:55 p.m. UTC | #1
Hi,

On Fri, 29 Nov 2019 at 22:06, Rosen Penev <rosenp@gmail.com> wrote:
>
> Allows GCC to check the formats by switching to a define, which is a
> constant expression.
>
> Fixes:
>
> warning: format not a string literal, argument types not checked
> [-Wformat-nonliteral]
>   207 |  snprintf(buf, sizeof(buf), tmpl, include->path);
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  includes.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/includes.c b/includes.c
> index 23b2244..1e759fb 100644
> --- a/includes.c
> +++ b/includes.c
> @@ -188,11 +188,11 @@ run_include(struct fw3_include *include)
>  {
>         int rv;
>         struct stat s;
> -       const char *tmpl =
> -               "config() { "
> -                       "echo \"You cannot use UCI in firewall includes!\" >&2; "
> -                       "exit 1; "
> -               "}; . %s";
> +       #define tmpl \
> +               "config() { " \
> +                       "echo \"You cannot use UCI in firewall includes!\" >&2; " \
> +                       "exit 1; " \
> +               "}; . %s"

defines are global, so they should be at top of the file, use caps for
the name, and have a less generic name than "templ" (or "format").
Same comment for the other patches doing the same thing.


Regards
Jonas
Rosen Penev Dec. 2, 2019, 2:08 a.m. UTC | #2
> On Dec 1, 2019, at 5:55 AM, Jonas Gorski <jonas.gorski@gmail.com> wrote:
> 
> Hi,
> 
>> On Fri, 29 Nov 2019 at 22:06, Rosen Penev <rosenp@gmail.com> wrote:
>> 
>> Allows GCC to check the formats by switching to a define, which is a
>> constant expression.
>> 
>> Fixes:
>> 
>> warning: format not a string literal, argument types not checked
>> [-Wformat-nonliteral]
>>  207 |  snprintf(buf, sizeof(buf), tmpl, include->path);
>> 
>> Signed-off-by: Rosen Penev <rosenp@gmail.com>
>> ---
>> includes.c | 10 +++++-----
>> 1 file changed, 5 insertions(+), 5 deletions(-)
>> 
>> diff --git a/includes.c b/includes.c
>> index 23b2244..1e759fb 100644
>> --- a/includes.c
>> +++ b/includes.c
>> @@ -188,11 +188,11 @@ run_include(struct fw3_include *include)
>> {
>>        int rv;
>>        struct stat s;
>> -       const char *tmpl =
>> -               "config() { "
>> -                       "echo \"You cannot use UCI in firewall includes!\" >&2; "
>> -                       "exit 1; "
>> -               "}; . %s";
>> +       #define tmpl \
>> +               "config() { " \
>> +                       "echo \"You cannot use UCI in firewall includes!\" >&2; " \
>> +                       "exit 1; " \
>> +               "}; . %s"
> 
> defines are global
Unfortunately 
> , so they should be at top of the file, use caps for
> the name, and have a less generic name than "templ" (or "format").
> Same comment for the other patches doing the same thing.
I’ll see about doing that.
> 
> 
> Regards
> Jonas
diff mbox series

Patch

diff --git a/includes.c b/includes.c
index 23b2244..1e759fb 100644
--- a/includes.c
+++ b/includes.c
@@ -188,11 +188,11 @@  run_include(struct fw3_include *include)
 {
 	int rv;
 	struct stat s;
-	const char *tmpl =
-		"config() { "
-			"echo \"You cannot use UCI in firewall includes!\" >&2; "
-			"exit 1; "
-		"}; . %s";
+	#define tmpl \
+		"config() { " \
+			"echo \"You cannot use UCI in firewall includes!\" >&2; " \
+			"exit 1; " \
+		"}; . %s"
 
 	char buf[PATH_MAX + sizeof(tmpl)];