Search code examples
cgcccompiler-warningsgcc-warninglinux-distro

Warning "format not a string literal and no format arguments" not appearing on latest gcc version


In my code I use the following line to print a char readbuffer[1]; array (char array with size 1):

printf(readbuffer);

This compiles and works without an issue on my pc (Arch Linux, gcc version 7.3.1+20180406-1). However, when I submitted my assignment containing this code to my instructor, he in fact got a compiler warning compiling my code:

shell.c:89:20: warning: format not a string literal and no format arguments [-Wformat-security]
         printf(readbuffer);

He is using the gcc/clang version from 16.04 LTS release. We both used the same compiler flags.

Why is this? Is this suddenly not an issue anymore in the new gcc version? If so, why not?

Just a note: I don't want to know how to solve this issue, but just want to know why the warning is inconsistent over gcc versions.


Solution

  • This is not caused by a difference in GCC versions. Rather, Ubuntu has modified GCC to enable -Wformat -Wformat-security by default. If you pass those options on Arch Linux, you should see the same behaviour there.