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中的字符数。



相关文章:

  • 2021-06-18
  • 2021-10-29
  • 2022-12-23
  • 2021-10-31
  • 2021-11-15
  • 2021-08-13
  • 2021-09-30
  • 2021-07-10
猜你喜欢
  • 2022-02-28
  • 2021-06-23
  • 2021-10-22
  • 2022-12-23
  • 2021-10-26
  • 2021-03-31
  • 2021-05-04
相关资源
相似解决方案