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 provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

To get samples and instructions for installing them:

  • On the Visual Studio Help menu, click Samples.

    For more information, see Visual Studio Samples.

  • The most recent version and complete list of samples is available online from the Visual Studio 2008 Samples page.

  • You can also locate samples on your computer's hard disk. By default, samples and a Readme file are copied into a folder under \Program Files\Visual Studio 9.0\Samples\. For Express editions of Visual Studio, all samples are located online.

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


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

See Also


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


Other Resources

General Samples