gcc 7.4.0中相对于gcc 5.4.9的新警告

问题描述 投票:0回答:1

几天前,我将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 ());
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

您能帮助我了解什么是警告以及如何解决?谢谢

gcc gcc-warning
1个回答
0
投票

您可以阅读HERE,GCC 7.1引入了Wformat-overflow选项。这就是为什么现在向您发出警告。

© www.soinside.com 2019 - 2024. All rights reserved.