
[英]warning: '__builtin_snprintf' output may be truncated before the last format character [-Wformat-truncation=]
[英]warning: ‘/name0’ directive output may be truncated writing 10 bytes into a region of size between 1 and 4096 [-Wformat-truncation=]
#DEFINE LENGTH 4096
warning: ‘/name0’ directive output may be truncated writing 10 bytes into a region
of size between 1 and 4096 [-Wformat-truncation=]
snprintf(head_list->cname, LENGTH, "%s/name0", cpath);
^~~~~~~~~~
gcc 发出此警告。 如何在不使用-Wformat-truncation=
选项的情况下解决这个问题?
cpath
是一个4096大小的字符
由于cpath
的最大长度为 4096 个字符,因此将/name0
附加到它的末尾会固有地创建一个可以超过 4096 个字符并且不能放入head_list->cname
的字符串
如果您确定cpath
不能超过 4090 个字符,请告诉 gcc关闭该特定行的警告
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-truncation"
snprintf(head_list->cname, LENGTH, "%s/name0", cpath);
assert(strlen(cpath) <= 4090);
#pragma GCC diagnostic pop
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.