[PATCH 1/3] fix literal error warning

Michael Tokarev mjt at tls.msk.ru
Tue Jul 31 13:32:26 UTC 2012


31.07.2012 17:15, manuel.f.zerpies at ww.stud.uni-erlangen.de wrote:
> From: Manuel Zerpies <manuel.f.zerpies at ww.stud.uni-erlangen.de>
> 
> compiling with gcc >= 4.4.3 the warning "format not a string literal
> and no format arguments" is thrown. This patch fixes that.
> 
[]
> index 0b1c4aa..a67e8b4 100644
> --- a/applets/usage_pod.c
> +++ b/applets/usage_pod.c
> @@ -71,7 +71,7 @@ int main(void)
>  		} else {
>  			printf(", ");
>  		}
> -		printf(usage_array[i].aname);
> +		printf("%s", usage_array[i].aname);

This can be replaced with fputs().

>  		col += len2;
>  	}
>  	printf("\n\n");
(and this too).

> diff --git a/archival/libarchive/data_extract_to_command.c b/archival/libarchive/data_extract_to_command.c
> index a2ce33b..354e958 100644
> --- a/archival/libarchive/data_extract_to_command.c
> +++ b/archival/libarchive/data_extract_to_command.c
> @@ -38,7 +38,7 @@ static const char *const tar_var[] = {
>  static void xputenv(char *str)
>  {
>  	if (putenv(str))
> -		bb_error_msg_and_die(bb_msg_memory_exhausted);
> +		bb_error_msg_and_die("%s", bb_msg_memory_exhausted);

And this, and many other similar warnings, are just silly.
Yes, gcc can't verify the format string, but it is declared
as constant for a reason.  These changes (all around bb_msg_*)
are just adding code without fixing anything.  In my opinion,
gcc should be fixed instead, to at least treat const char[]
fmt string as non-dangerous.

> diff --git a/libbb/dump.c b/libbb/dump.c
> index 7e43564..91efe41 100644
> --- a/libbb/dump.c
> +++ b/libbb/dump.c
> @@ -613,7 +613,7 @@ static void display(priv_dumper_t* dumper)
>  							printf(pr->fmt, (char *) bp);


>  							break;
>  						case F_TEXT:
> -							printf(pr->fmt);
> +							printf("%s", pr->fmt);

If you "fixed" this, how about fixing the one right above it too (shown),
and all the rest?  There's no reason to fix only one of them, and other
cases can't be fixed easily.

/mjt


More information about the busybox mailing list