C++ 'strcpy' gives a Warning (C4996)

前端 未结 9 1121
孤城傲影
孤城傲影 2020-12-03 08:15

I am getting this warning but all functions working properly .

what does this really means?

\'strcpy\': This function or variable may be unsafe. 
Con         


        
9条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-03 08:32

    While strcpy is a common string function, it has a history of being the source of many bugs and security holes in software (due to the ease of buffer overflows).

    Microsoft, in an effort to promote safer coding in C and C++ has provided a suite of replacement functions for the dangerous string methods. Typically they have the original name postpended with _s. Hence the Microsoft secure version of strcpy is strcpy_s as recommended in the warning. Note this a Microsoft specific feature, it's not ubiquitious.

    You've got a few options.

    1. DEFINE _CRT_SECURE_NO_WARNINGS if you don't want to care about it, leaving the possibility of the security issues in your software.
    2. Replace your string functions with the secure ones, leaving your software less portable as a consequence
    3. Wrap the secure string functions and use the wrappers everywhere, providing enhanced security on Windows platforms, and falling back to the traditional versions on other platforms. The wrapper functions could be via a MACRO or compiled functions.

    I typically do #3.

提交回复
热议问题