AddressSanitizer 已知問題

注意

請傳送意見反應 ,瞭解您未來版本想要看到的內容,並在 遇到問題時回報錯誤

不相容的選項和功能

這些選項和功能與 /fsanitize=address 不相容,因此應該停用或避免。

標準程式庫支援

MSVC 標準程式庫 (STL) 已部分啟用,以瞭解 AddressSanitizer 並提供其他檢查。 如需詳細資訊,請參閱 container-overflow 錯誤

當批註停用或不支援的版本時,STL 程式碼中引發的 AddressSanitizer 例外狀況仍會識別真正的 Bug。 不過,它們不如可能那麼精確。

此範例示範缺乏精確度,以及啟用注釋的優點:

// Compile with: cl /fsanitize=address /Zi
#include <vector>

int main() {   
    // Create a vector of size 10, but with a capacity of 20.    
    std::vector<int> v(10);
    v.reserve(20);

    // In versions prior to 17.2, MSVC ASan does NOT raise an exception here.
    // While this is an out-of-bounds write to 'v', MSVC ASan
    // ensures the write is within the heap allocation size (20).
    // With 17.2 and later, MSVC ASan will raise a 'container-overflow' exception:
    // ==18364==ERROR: AddressSanitizer: container-overflow on address 0x1263cb8a0048 at pc 0x7ff6466411ab bp 0x005cf81ef7b0 sp 0x005cf81ef7b8
    v[10] = 1;

    // Regardless of version, MSVC ASan DOES raise an exception here, as this write
    // is out of bounds from the heap allocation.
    v[20] = 1;
}

Windows 版本

由於特定 Windows 版本有相依性,因此支援著重于 Windows 10。 MSVC AddressSanitizer 已在 10.0.14393 (RS1) 和 10.0.21323 (發行前測試人員組建) 上進行測試。 如果您遇到問題,請回報錯誤

記憶體使用量

AddressSanitizer 執行時間不會在執行期間將記憶體釋放回 OS。 從 OS 的觀點來看,它看起來可能會有記憶體流失。 此設計決策是刻意的,因此不要預先配置所有必要的記憶體。

AddressSanitizer 執行時間 DLL 位置

運行 clang_rt.asan*.dll 時間檔案會安裝在 中的 %VSINSTALLDIR%\VC\Tools\MSVC\<version>\bin\<host-arch>\<target-arch>\ 編譯器旁邊。 這些位置位於偵錯會話的路徑上,以及在 Visual Studio 開發人員命令提示字元中。 這些檔案永遠不會放在 或 C:\Windows\SysWOW64C:\Windows\System32

自訂屬性工作表支援

Visual Studio IDE 中的 [屬性管理員] 視窗可讓您將自訂 .props 檔案新增至專案。 即使 顯示 [啟用位址清理器 ] 屬性 ( <EnableASAN> ) ,但組建不會接受它。 這是因為自訂 .props 檔案會包含在 之後 Microsoft.cpp.props ,它會使用 <EnableASAN> 值來設定其他屬性。

因應措施是,您可以在專案的根目錄中建立 Directory.Build.props 檔案,以定義 <EnableASAN> 屬性。 如需詳細資訊,請參閱 自訂 C++ 組建

另請參閱

AddressSanitizer 概觀
AddressSanitizer 組建和語言參考
AddressSanitizer 執行時間參考
AddressSanitizer 陰影位元組
AddressSanitizer 雲端或分散式測試
AddressSanitizer 偵錯工具整合
AddressSanitizer 錯誤範例