几天前,我将UBUNTU发行版从16.04.12更新为18.04.01。
此更新导致从gcc-5.4.0过渡到gcc-7-4-0。
在此系统中,我以前使用c开发了一个应用程序,并使用-Wall选项进行了编译,没有生成警告。
现在我收到以下警告:
src/load_input_file.c: In function ‘load_input_file’:
src/load_input_file.c:60:23: warning: ‘%s’ directive writing up to 499 bytes into a region of size 196 [-Wformat-overflow=] o
sprintf(str,"cp %s %s",fileName,inputData.outDir);
^~ ~~~~~~~~~
In file included from /usr/include/stdio.h:862:0,
from hdr/load_input_file.h:3,
from src/load_input_file.c:1:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:33:10: note: ‘__builtin___sprintf_chk’ output 5 or more bytes (assuming 504) into a destination of size 200
return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
__bos (__s), __fmt, __va_arg_pack ());
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
您能帮助我了解什么是警告以及如何解决?谢谢
您可以阅读HERE,GCC 7.1引入了Wformat-overflow
选项。这就是为什么现在向您发出警告。