Describe the bug
ASan does not fire when writing to uninitialized memory in a basic_string, unlike with vector.
Command-line test case
C:\Temp>type repro.cpp
#include <vector>
#include <string>
int main()
{
// This crashes (expectedly)
//std::vector<int> vec;
//vec.reserve(100);
//vec.data()[50] = 1;
// This does not crash (it should crash, like `vector`)
std::basic_string<char> myString;
myString.reserve(100);
char* data = &myString[0];
data[50] = 'A';
}
C:\Temp>cl /EHsc /Zi /fsanitize=address .\repro.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.43.34618 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
repro.cpp
Microsoft (R) Incremental Linker Version 14.43.34618.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:repro.exe
/debug
/InferAsanLibs
repro.obj
C:\Temp>.\repro.exe
<no ASan failure thrown>
Expected behavior
ASan should throw a container-overflow-type error due to a WRITE on an uninitialized section of container memory.
STL version
Microsoft Visual Studio Enterprise 2022
Version 17.13.0 Preview 2.1
Additional context
This bug was discovered while developing the basic_string test case for #5241, and has already been discussed internally.
Describe the bug
ASan does not fire when writing to uninitialized memory in a
basic_string, unlike withvector.Command-line test case
Expected behavior
ASan should throw a
container-overflow-type error due to aWRITEon an uninitialized section of container memory.STL version
Additional context
This bug was discovered while developing the
basic_stringtest case for #5241, and has already been discussed internally.