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 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. |
To build and run this sample
Open the solution file, SecureCRT.sln, in the Visual Studio development environment.
From the Build menu, click Build Solution.
From the Projects menu, click Properties.
Under Configuration Properties, select Debugging.
Specify the arguments to pass to the program in the Command Arguments text box (“if find.cpp” is a good first choice).
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.
This application can also be run from the command line: SecureCRT.exe if find.cpp
Requirements
Keywords
strcpy_s, strncpy_s, fopen_s, _splitpath_s, sprintf_s, getenv_s, strcat_s, itoa_s, _set_invalid_parameter_handler