C4996 (function unsafe) warning for strcpy but not for memcpy

前端 未结 7 2267
青春惊慌失措
青春惊慌失措 2020-11-27 08:03

I am writing code in VS2010 and I happen to see after compilation compiler gives me C4996 warning (\"This function or variable may be unsafe\") for strcpy and sprintf calls.

7条回答
  •  难免孤独
    2020-11-27 08:55

    Because strcpy and sprintf really are unsafe functions, it depends on the content of the string to not overflow. Instead you should use strncpy and snprintf to make sure it does not overwrite the memory.

    While memcpy is not this case, it has the length so it does not overwrite memory as long as the length is correct.

提交回复
热议问题