Udostępnij za pośrednictwem


Safe Libraries: Standard C++ Library

Several enhancements have been made to the libraries that ship with Visual C++, including the Standard C++ Library, to make them more secure.

Several methods in the Standard C++ Library have been identified as potentially unsafe because they could lead to a buffer overrun or other code defect. The use of these methods is discouraged, and new, more secure methods have been created to replace them. These new methods all end in _s.

Several enhancements have also been made to make iterators and algorithms more secure. For more information, see Checked Iterators and Debug Iterator Support.

Remarks

The following table lists the Standard C++ Library methods that are potentially unsafe, as well as their safer equivalent:

Potentially unsafe method

Safer equivalent

basic_string::copy

basic_string::_Copy_s

basic_istream::read

basic_istream::_Read_s

basic_istream::readsome

basic_istream::_Readsome_s

basic_streambuf::sgetn

basic_streambuf::_Sgetn_s

basic_streambuf::xsgetn

basic_streambuf::_Xsgetn_s

char_traits::copy

char_traits::_Copy_s

char_traits::move

char_traits::_Move_s

ctype::narrow

ctype::_Narrow_s

ctype::do_narrow

ctype::_Do_narrow_s

ctype::widen

ctype::_Widen_s

ctype::do_widen

ctype::_Do_widen_s

If you call any one of the potentially unsafe methods above, or if you use iterators incorrectly, the compiler will generate Compiler Warning (level 3) C4996. For information on how to disable these warnings, see _SCL_SECURE_NO_WARNINGS.

In This Section

_SCL_SECURE_NO_WARNINGS

Checked Iterators

Debug Iterator Support

See Also

Reference

Standard C++ Library Overview