Findings during my work
Wentao Sun.
1. ZeroMemory on Windows is only a macro:
fills block with zeros
#if defined(OSMac_) || defined(OSLinux_)
memset(pVoid, 0, length);
#else
::ZeroMemory(pVoid, length);
#endif
最后用memset全部清零。
在微软内部是用一个RtlZeroMemory的宏完成,而且有一些类似的宏。
2.
wcscpy_s何以安全?
errno_t wcscpy_s(
wchar_t *strDestination,
size_t numberOfElements,
const wchar_t *strSource
);
=============================
Parameters
strDestination
Location of destination string buffer
numberOfElements
Size of the destination string buffer.
strSource
Null-terminated source string buffer.
inline void __cdecl wcscpy_s(_Out_cap_(_S1max) wchar_t *_S1, _In_ size_t _S1max, _In_z_ const wchar_t *_S2)
{
ATLMFC_CRT_ERRORCHECK(::wcscpy_s(_S1, _S1max, _S2));
}
_Check_return_wat_ _CRTIMP_ALTERNATIVE errno_t __cdecl wcscpy_s(_Out_z_cap_(_SizeInWords) wchar_t * _Dst, _In_ rsize_t
_SizeInWords, _In_z_ const wchar_t * _Src);
第二个参数表示的是目标string的长度,而不是Number of characters to be copied.
比较:
wchar_t *wcsncpy(
wchar_t *strDest,
const wchar_t *strSource,
size_t count
);
长度信息放在最后的一个参数中,表示的是准备copy到目标string中的src string中的字符数。