How to get the same result of strcpy () with strcpy_s ()?

3

I downloaded a code in C ++ from the internet and when I open the solution, it gives the following error:

  

Error C4996 'strcpy': This function or variable may be unsafe. Consider   using strcpy_s instead. To disable deprecation, use   _CRT_SECURE_NO_WARNINGS.

Following the statement, I modified the strcpy by strcpy_s . But it generated 2 other errors:

  

Error C2660 'strcpy_s': function does not get 2 arguments.

     

Error (active) E0304 no overloaded function instance   "strcpy_s" matches the list of arguments.

Why did the first error occur? What am I doing wrong?

Code:

strcpy((char*)m_pOriginalCVar->pszName, m_szDummyName);
    
asked by anonymous 20.07.2017 / 19:28

1 answer

3

It would look something like this:

strcpy_s((char*)m_pOriginalCVar->pszName, /*tamanho aqui*/, m_szDummyName);

This size should be the size of (char*)m_pOriginalCVar->pszName or the size of m_szDummyName , usually whichever is smaller and that makes more sense, if the function is greater does not miracle and the programmer error in the good choice will bring the same consequences of the insecure function.

It may be that you have other things to look out for to make sure the function is able to perform the secure copy, the function will not do anything unsafe, and the programmer should make sure everything is in order. The question has no details that might help.

The error occurred because strcpy() is insecure .

Documentation . And Microsoft documentation .

    
20.07.2017 / 19:36