This is the mail archive of the gcc-bugs@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]

[Bug c/79554] Zero length format string passed to fprintf under if statement causes error message


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("");

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