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.