当前位置:   article > 正文

gcc7.4.1出现截断错误_-werror=format-truncation=

-werror=format-truncation=

gcc7.4.1出现截断错误

在升级使用全志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

编译通过。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/496708
推荐阅读
相关标签
  

闽ICP备14008679号