output truncated before terminating nul copying 6 bytes from a string of the same length [-Werror=s

output truncated before terminating nul copying 6 bytes from a string of the same length [-Werror=s,第1张

output truncated before terminating nul copying 6 bytes from a string of the same length [-Werror=s

编译某项目代码时出现下面问题,

/data/chw/cnstream6_220/framework/unitest/test_base.cpp: In function ‘std::pair > CreateTempFile(const string&)’:
/data/chw/cnstream6_220/framework/unitest/test_base.cpp:63:10: error: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying 6 bytes from a string of the same length [-Werror=stringop-truncation]
   strncpy(filename + filename_prefix.size(), "XXXXXX", 6);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors
make[2]: *** [framework/unitest/CMakeFiles/cnstream_core_test.dir/build.make:323: framework/unitest/CMakeFiles/cnstream_core_test.dir/test_base.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:261: framework/unitest/CMakeFiles/cnstream_core_test.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

 从错误提示中也能看到,all warnings being treated as errors,所有警告当成错误了。解决方法是在cmakelists.txt中下面定义,no-stringop-truncation也就是不把这个stringop-truncation当成error了。

add_definitions(-Wno-stringop-truncation)

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5657651.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存