How to circumvent format-truncation warning in GCC?

前端 未结 2 1990
一向
一向 2020-12-15 18:02

I\'m getting the following gcc format-truncation warning:

test.c:8:33: warning: ‘/input’ directive output may be truncated writing 6 bytes into a region of s         


        
2条回答
  •  执笔经年
    2020-12-15 18:59

    This error is only triggered when length-limited *printf functions are called (snprintf, vsnprintf). In other words, it is not an indication that you may be writing into unallocated memory, as may happen with sprintf; it only notifies you that you aren't paying attention to when snprintf may be doing is job and truncating.

    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.

提交回复
热议问题