Here is my code:
void subroutine(const char *message) { printf(message); }
And here is the error I get:
Error: In function ' ': warning: format not a string literal and no format arguements [-Wformat-security]
What is the error here? I can’t solve it.
Any suggestions?
You should use
Longer explanation:
printftreats its first argument as format specifier. If you are lucky and the message doesn’t contain%sor other substrings special forprintf, the message will be printed “as is”.But if the
messagecontains something like that, your program will try to interpret other arguments toprintfas the parameters. As there are no actual arguments, it will, for example, consider some arbitrary memory location as a pointer, and try to dereference it. This would in the best case lead to a crash; in the worst case, this may leak some sensitive data.(
printfcan even overwrite some memory if%nis encountered in the format string.)