[PATCH] Avoid -Werror=format-security errors in libcpp

Jeff Law law@redhat.com
Thu Jan 15 17:44:00 GMT 2015


On 01/15/15 04:19, Jakub Jelinek wrote:
> Hi!
>
> With the addition of build libcpp, my build failed because of distro default
> flags of -Werror=format-security.
>
> The first hunk is I think no big deal, making it const makes the warning
> go away.
>
> The second hunk is more controversial, as even making message const doesn't
> help with the warning.  There is another option of using "%s" and
> _( instead of N_ in message, or just keep it as is and I can keep the second
> hunk as local hack.
>
> Thoughts on this?
>
> 2015-01-15  Jakub Jelinek  <jakub@redhat.com>
>
> 	* macro.c (create_iso_definition): Make paste_op_error_msg var
> 	const.
> 	* expr.c (cpp_classify_number): Avoid -Wformat-security warning.
I'd go with the patch as-is.  Approved.

jeff
>
> --- libcpp/macro.c.jj	2015-01-14 11:01:34.000000000 +0100
> +++ libcpp/macro.c	2015-01-14 14:22:19.286949884 +0100
> @@ -2947,7 +2947,7 @@ create_iso_definition (cpp_reader *pfile
>     cpp_token *token;
>     const cpp_token *ctoken;
>     bool following_paste_op = false;
> -  const char *paste_op_error_msg =
> +  const char *const paste_op_error_msg =
>       N_("'##' cannot appear at either end of a macro expansion");
>     unsigned int num_extra_tokens = 0;
>
> --- libcpp/expr.c.jj	2015-01-14 11:01:34.000000000 +0100
> +++ libcpp/expr.c	2015-01-14 14:35:52.851002344 +0100
> @@ -672,16 +672,17 @@ cpp_classify_number (cpp_reader *pfile,
>         if ((result & CPP_N_WIDTH) == CPP_N_LARGE
>   	  && CPP_OPTION (pfile, cpp_warn_long_long))
>           {
> -          const char *message = CPP_OPTION (pfile, cplusplus)
> -				? N_("use of C++11 long long integer constant")
> -		                : N_("use of C99 long long integer constant");
> -
>   	  if (CPP_OPTION (pfile, c99))
>               cpp_warning_with_line (pfile, CPP_W_LONG_LONG, virtual_location,
> -				   0, message);
> +				   0, CPP_OPTION (pfile, cplusplus)
> +				      ? "use of C++11 long long integer constant"
> +				      : "use of C99 long long integer constant");
>             else
>               cpp_pedwarning_with_line (pfile, CPP_W_LONG_LONG,
> -				      virtual_location, 0, message);
> +				      virtual_location, 0,
> +				      CPP_OPTION (pfile, cplusplus)
> +				      ? "use of C++11 long long integer constant"
> +				      : "use of C99 long long integer constant");
>           }
>
>         result |= CPP_N_INTEGER;
>
>
> 	Jakub
>



More information about the Gcc-patches mailing list