我收到以下gcc格式 - 截断警告:
test.c:8:33: warning: ‘/input’ directive output may be truncated writing 6 bytes into a region of size between 1 and 20 [-Wformat-truncation=]
snprintf(dst, sizeof(dst), "%s-more", src);
^~~~~~
test.c:8:3: note: ‘snprintf’ output between 7 and 26 bytes into a destination of size 20
snprintf(dst, sizeof(dst), "%s-more", src);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Run Code Online (Sandbox Code Playgroud)
像这样的代码:
char dst[20];
char src[20];
scanf("%s", src);
snprintf(dst, sizeof(dst), "%s-more", src);
printf("%s\n", dst);
Run Code Online (Sandbox Code Playgroud)
我知道它可能会被截断 - 但这正是我首先使用snprintf的原因.有没有办法让编译器明白这是预期的(不使用编译指示或-Wno格式截断)?
我想知道编译一个带有多个结果二进制文件的整个 C/C++ 项目的所有代码文件的路径。我知道https://github.com/rizsotto/Bear等人,您可以将其环绕在“make”调用中,并告诉您 gcc/g++ 调用,但它们当然只向我显示已编译的 C/C++ 文件- 我怎样才能找出编译需要哪些头文件并最终出现在生成的二进制文件之一中?