This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] generated string libraries & -Wformat


This bootstraps in Linux i686 & I can use -Wno-format-contains-nul to
suppress that warning.  OK?

Bruce Korb wrote:
> Hello,
> 
> I mess around with a lot of generated code.  That means I do automated
> construction of libraries that use literal strings.  In order to
> reduce address fixups, I often put all the literal strings into one long
> string with each piece separated from the others with a NUL byte.
> Unfortunately, I am then constrained from using ``-Wformat'' because
> it fears I might accidentally be doing something wrong.
> 
> I believe the attached patch is sufficient to implement
>    -Wno-format-contains-nul
> (I am bootstrapping GCC and will be testing for a few hours.)
> 
> I'd like to hear any complaints about the change before I
> spend too much time polishing it.  Thank you!
> 
> Regards, Bruce

2007-03-24  Bruce Korb  <bkorb@gnu.org>

	* c-format.c (set_Wformat): set warn_format_contains_nul to -Wformat
	setting
	(check_format_info_main): changed embedded NUL byte warning to test
	for OPT_Wformat_contains_nul
	* c.opt: define Wformat-contains-nul
	* c-opts.c (c_common_post_options): complain if -Wformat-contains-nul
	is set and -Wformat is not set

> Index: c-format.c
> ===================================================================
> --- c-format.c  (revision 123186)
> +++ c-format.c  (working copy)
> @@ -43,6 +43,7 @@
>    if (setting != 1)
>      {
>        warn_format_nonliteral = setting;
> +      warn_format_contains_nul = setting;
>        warn_format_security = setting;
>        warn_format_y2k = setting;
>      }
> @@ -1482,7 +1483,7 @@
>        if (*format_chars == 0)
>         {
>           if (format_chars - orig_format_chars != format_length)
> -           warning (OPT_Wformat, "embedded %<\\0%> in format");
> +           warning (OPT_Wformat_contains_nul, "embedded %<\\0%> in format");
>           if (info->first_arg_num != 0 && params != 0
>               && has_operand_number <= 0)
>             {
> Index: c.opt
> ===================================================================
> --- c.opt       (revision 123186)
> +++ c.opt       (working copy)
> @@ -216,6 +216,10 @@
>  C ObjC C++ ObjC++ Var(warn_format_nonliteral) Warning
>  Warn about format strings that are not literals
> 
> +Wformat-contains-nul
> +C ObjC C++ ObjC++ Var(warn_format_contains_nul)
> +Warn about format strings that contain NUL bytes
> +
>  Wformat-security
>  C ObjC C++ ObjC++ Var(warn_format_security) Warning
>  Warn about possible security problems with format functions
> Index: c-opts.c
> ===================================================================
> --- c-opts.c    (revision 123186)
> +++ c-opts.c    (working copy)
> @@ -1106,6 +1106,8 @@
>                "-Wformat-zero-length ignored without -Wformat");
>        warning (OPT_Wformat_nonliteral,
>                "-Wformat-nonliteral ignored without -Wformat");
> +      warning (OPT_Wformat_contains_nul,
> +              "-Wformat-contains-nul ignored without -Wformat");
>        warning (OPT_Wformat_security,
>                "-Wformat-security ignored without -Wformat");
>      }
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]