gcc7.4.1出现截断错误

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

编译通过。

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值