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 patterned after usage of "format-nonliteral" 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"); }