Share via


SecureCRT Sample: Converting Deprecated CRT Functions to their _s Counterparts

This sample demonstrates how to convert CRT functions which have been deprecated for security reasons to their _s counterparts. It covers the conversion of the following functions: strcpy, strncpy, fopen, _splitpath, sprintf, getenv, strcat, _creat, and itoa. It also demonstrates the use of _set_invalid_parameter_handler, another Secure CRT addition.

This sample implements the Boyer-Moore string matching algorithm using standard CRT functions.

Security noteSecurity Note

This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.

To get samples and instructions for installing them:

To access samples from Visual Studio

  • On the Help menu, click Samples.

    By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.

  • For the most recent version of this sample and a list of other samples, see Visual Studio Samples on the MSDN Web site.

To build and run this sample

  1. Open the solution file, SecureCRT.sln, in the Visual Studio development environment.

  2. From the Build menu, click Build Solution.

  3. From the Projects menu, click Properties.

  4. Under Configuration Properties, select Debugging.

  5. Specify the arguments to pass to the program in the Command Arguments text box ("if find.cpp" is a good first choice).

  6. From the Debug menu, click Start Without Debugging. The application will search each line of the file (find.cpp, in this case) for the text you specified ("if") in the Command Arguments and write all matches to a file (find.cpp.match, in this case) in the working directory.

  7. This application can also be run from the command line: SecureCRT.exe if find.cpp

Keywords

strcpy_s, strncpy_s, fopen_s, _splitpath_s, sprintf_s, getenv_s, strcat_s, itoa_s, _set_invalid_parameter_handler

See Also

Reference

strcpy_s, wcscpy_s, _mbscpy_s

strncpy_s, _strncpy_s_l, wcsncpy_s, _wcsncpy_s_l, _mbsncpy_s, _mbsncpy_s_l

fopen_s, _wfopen_s

_splitpath_s, _wsplitpath_s

sprintf_s, _sprintf_s_l, swprintf_s, _swprintf_s_l

getenv_s, _wgetenv_s

strcat_s, wcscat_s, _mbscat_s

_itoa_s, _i64toa_s, _ui64toa_s, _itow_s, _i64tow_s, _ui64tow_s

_set_invalid_parameter_handler

Other Resources

General Samples