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

前端 未结 7 2266
青春惊慌失措
青春惊慌失措 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:51

    Include in header "stdafx.h" definition

    #define _CRT_SECURE_NO_WARNINGS
    

    As for the difference of strcpy and memcpy then the last function has third parameter that explicitly specifies how many characters must be copied. The first function has no information how many characters will be copied from the source string to the destination string so in general case there is a possibility that the memory allocated for the destination string will be overwritten.

提交回复
热议问题