This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/79554] Zero length format string passed to fprintf under if statement causes error message
- From: "cnconlinux at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 21 Feb 2017 13:06:41 +0000
- Subject: [Bug c/79554] Zero length format string passed to fprintf under if statement causes error message
- Auto-submitted: auto-generated
- References: <bug-79554-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79554
--- Comment #3 from Андрей Доценко <cnconlinux at gmail dot com> ---
(In reply to Jakub Jelinek from comment #1)
> In the first macro fmt_ isn't defined at all (nor there is a fmt_ variable),
> so I doubt it compiles at all.
> And, in the second macro, the warning is 100% correct, fmt_ is a non-const
> variable, -Wformat-security is a FE warning, so can't rely on any
> optimizations etc. Probably const char *const fmt_ = fmt; should work,
> because then it should be able to look at the var's initializer.
I've simplified the code to make this report, so I've made a mistake. The code
is meant to be:
#define PRINT_CHANGE(fmt, args...) \
do { \
fprintf(DEBUG_STREAM, "%s(", __FUNCTION__); \
if (strcmp(fmt, "") != 0) { \
fprintf(DEBUG_STREAM, fmt, ##args); \
} \
fprintf(DEBUG_STREAM, ")\n"); \
} while (0)
PRINT_CHANGE("");