Use of wcstombs

Source: Internet
Author: User

Converts a sequence of wide characters to a corresponding sequence of multibyte characters.

 
Size_t wcstombs (char * mbstr, const wchar_t * wcstr, size_t count );
Parameters
Mbstr
The address of a sequence of multibyte characters.
Wcstr
The address of a sequence of wide characters.
count

the maximum number of bytes that can be stored in the multibyte output string.

it is easy to use. However, errors often occur when the third parameter is used.

coverity reports a potential out-of-bounds error.

 STD: String fullpathfilename; const unsigned int nmaxpathlen = 255; wchar_t szpath [nmaxpathlen + 1] = {0 }; getmodulefilename (null, szpath, nmaxpathlen); wchar_t * P = wcsrchr (szpath, '\'); * p = 0; unsigned int _ dsize = (nmaxpathlen + 1) * 2; // error char * _ DEST = new char [_ dsize]; memset (_ DEST, 0, _ dsize); wcstombs (_ DEST, szpath, _ dsize ); fullpathfilename. append (_ DEST); fullpathfilename. append ("\ memorydrlocation"); Delete [] _ DEST; _ DEST = NULL; 

the error here is that the third parameter of the function requires the byte length of the array. In fact, it is the number of elements in the required array.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.