Deprecation of mbstowcs and _mbstowcs
Background
The mbstowcs and _mbstowcs functions in the C runtime library (CRT) are used to convert multibyte character strings to wide character strings. These functions have been deprecated in Visual Studio 2019 version 16.8 and later, and they will be removed in a future version of Visual Studio.
Deprecation Details
The mbstowcs and _mbstowcs functions have been deprecated due to security concerns. These functions do not handle input validation correctly, which can lead to buffer overflows and other security vulnerabilities. Additionally, these functions are not thread-safe, which can lead to race conditions and other concurrency issues.
Recommended Alternatives
Microsoft recommends that developers use the following alternatives to mbstowcs and _mbstowcs:
- mbstowcs_s and _mbstowcs_s_l: These functions are secure versions of mbstowcs and _mbstowcs, respectively. They perform input validation and are thread-safe.
- mbsrtowcs and _mbsrtowcs_l: These functions are similar to mbstowcs and _mbstowcs, but they allow the caller to specify the current locale. They are also secure and thread-safe.
Impact on Existing Code
If your code uses mbstowcs or _mbstowcs, you should update your code to use one of the recommended alternatives. Failure to do so may result in security vulnerabilities or other problems in future versions of Visual Studio.
Additional Resources
- mbstowcs, wcsmbstowcs, _mbstowcs_s, _wcsmbstowcs_s_l Functions
- Security Deprecations in Visual Studio 2019 version 16.8
Comments