sprintf_s with a buffer too small

后端 未结 6 1210
广开言路
广开言路 2021-02-08 12:03

The following code causes an error and kills my application. It makes sense as the buffer is only 10 bytes long and the text is 22 bytes long (buffer overflow).



        
6条回答
  •  执笔经年
    2021-02-08 12:29

    Looks like you're writing on MSVC of some sort?

    I think the MSDN docs for sprintf_s says that it assert dies, so I'm not too sure if you can programmatically catch that.

    As LBushkin suggested, you're much better off using classes that manage the strings.

提交回复
热议问题