How can I use strncat without buffer overflow concerns?

前端 未结 5 629
野趣味
野趣味 2020-12-03 05:33

I have a buffer, I am doing lot of strncat. I want to make sure I never overflow the buffer size.

char buff[64];

strcpy(buff, \"String 1\");

strncat(buff,          


        
5条回答
  •  甜味超标
    2020-12-03 06:14

    Hogan has answered the question sufficently; however, if you are worried about buffer overflows in strcat(...) you should equally be worried about buffer overflows in all the other string functions.

    Use strnlen(...) and strncpy(...) to really make sure you stay within your buffer. If you don't have a strnlen(...) function, write it.

提交回复
热议问题