赞
踩
在升级使用全志tina升级gcc编译器时出现了一个
error: ‘.’ directive output may be truncated writing 1 byte into a region of size between 0 and 16 [-Werror=format-truncation=]
的错误。
这个错误的出现sprintf函数引用导致的。
在多方查找之后,有人建议尝试一下三个方法
解决方法:1.我们可以检查snprintf的返回值,该值在错误时返回负值。
解决方法:2.将snprintf的dest buf 调大
解决方法:3.如果需要消除warning当成error的编译规则,在Makefile中去掉-Werror参数
我实际操作没办法解决掉。然后在国外论坛看到了一个
https://stackoverflow.com/questions/51534284/how-to-circumvent-format-truncation-warning-in-gcc
论坛地址。
上面说道了这段话
This error is only triggered when length-limited *printf functions are called (e.g. snprintf, vsnprintf). In other words, it is not an indication that you may be overflowing a buffer, as may happen with sprintf; it only notifies you that you aren’t checking whether snprintf is doing its job and truncating. (Side note: snprintf always null-terminates, so this can’t result in a non-terminated string.)
Knowing that, I’m much more sanguine about disabling it globally using -Wno-format-truncation, rather than trying to coax gcc into ignoring a specific instance.
我尝试着在makefile里添加
TARGET_CFLAGS += -Wno-format-truncation
编译通过。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。