• 微软的secure string IO functions


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



  • 相关阅读:
    字符串语法
    组合数
    并查集
    Java Collection HashMap源码分析
    Java 虚拟机 ClassLoader
    Java 多线程 Future
    Java 虚拟机 GC机制
    Java 基础 原生类型
    Java 多线程 死锁deadlock产生原因+避免方法
    Java 基础 基本类型vs引用类型,传值vs传引用
  • 原文地址:https://www.cnblogs.com/SunWentao/p/1298252.html
Copyright © 2020-2023  润新知