Correcting "format string is not a string literal" warning

Viewed 7614

I have a warning in my code that is driving me crazy:

int vasprintf_wrapper(char** bufptr, const char* fmt, va_list ap)
{
    // Do stuff...
    // ...
    return vasprintf(bufptr, fmt, ap);
}

Clang (3.6.0), complains with "format string is not a string literal", referring to the fmt argument that is being forwarded.

Naively, I tried to:

return vasprintf(bufptr, reinterpret_cast<const char[]>(fmt), ap);

Which of course doesn't compile.

What do I do? Disabling the warning altogether is not an option. I want to have the warning. But in this case, I would like to tell the compiler that I know what I'm doing ("famous last words" jokes aside...)

2 Answers
Related