Questions tagged [memory-sanitizer]

19 questions
53
votes
2 answers

Memory/Address Sanitizer vs Valgrind

I want some tool to diagnose use-after-free bugs and uninitialized bugs. I am considering Sanitizer(Memory and/or Address) and Valgrind. But I have very little idea about their advantages and disadvantages. Can anyone tell the main features,…
kayas
  • 703
  • 1
  • 5
  • 14
29
votes
3 answers

Using memory sanitizer with libstdc++

I wish to use the -fsanitize=memory flag in clang to analyse a program like the following: #include #include #include using namespace std; void writeToFile(){ ofstream o; o.open("dum"); o<<"test"<
soandos
  • 4,978
  • 13
  • 62
  • 96
3
votes
1 answer

Does `string s = std::to_string(1) + std::to_string(2)` use uninitialized memory

The question is, does the following snippet use uninitialized memory, as reported by Google's MemorySanitizer? Or is it a false positive?: main.cpp: #include #include using namespace std; int main() { string s0 =…
D.J. Elkind
  • 367
  • 2
  • 8
3
votes
2 answers

Why does the memory-sanitizer report use of an uninitialized value for std::map?

I'm using manjaro linux on x86-64. Memory-sanitizer in clang version 10.0.1 reported a use of uninitialized value error in std::map, which quite surprised me. Did I do something wrong? $ cat test.cpp #include int main() { std::map
Pac
  • 167
  • 4
3
votes
0 answers

Clang memory sanitizer bug with SSE intrinsics

Here is a piece of code that generates an internal compiler error if I compile and run it with clang having memory sanitizer enabled. It mainly just puts some data into an SSE register and calls a function to convert half floats to floats: int…
2
votes
0 answers

clang sanitize-blacklist is not ignoring a function

I am using clang 7.0.1-6 with -fsatize=memory and -fsanitize-blacklist to ignore unitialized memory in libc. Unfortunately it seems that msan does not ignore cap_init, or it's descendants. $ cat /buildslave/core-ci/build/core/blacklist…
cmouse
  • 672
  • 1
  • 6
  • 22
2
votes
1 answer

Memory sanitizer error: clang5 + msan + fwrite of structs with padding bytes

Minimum example: #include struct TFoo { bool Field1_ = false; uint64_t Field2_ = 0; }; int main() { TFoo Foo_{}; const char* filename = "text.txt"; std::ofstream f(filename); f.write((char*)(&Foo_),…
vladon
  • 8,158
  • 2
  • 47
  • 91
2
votes
0 answers

Memory Sanitizer use-of-uninitialized-value with ifstream

Here's a minimal example to reproduce - #include #include #include using namespace std; int main() { ifstream names("lol.txt"); if(!names) { cerr << "Not found\n"; return -1; } cout <<…
Abhinav Gauniyal
  • 7,034
  • 7
  • 50
  • 93
2
votes
2 answers

How can I practically use AddressSanitizer and MemorySanitizer?

AddressSanitizer and MemorySanitizer are very useful tools, but they require that the whole program be appropriately instrumented. (At least, for the Clang version of AddressSanitizer; see here in the MemorySanitizer docs and the "using private…
Josh Kelley
  • 56,064
  • 19
  • 146
  • 246
1
vote
1 answer

GNU compiler memory sanitizer is not available

When I try to build my c++ project with memory sanitizer using the CMake sanitizers modules here, I get this warning: MemorySanitizer is not available for GNU compiler. Although when I searched on google it is stated here that GNU compiler…
E. Tolga
  • 41
  • 4
1
vote
1 answer

How do I tell clang memory sanitizer to ignore data from certain libraries?

For example I'd like to ignore sqlite and zlib because I know they're well tested. I grabbed the zpipe.c example and built it like this. Keep in mind I'm using -lz and not building zlib myself. I'm only building zpipe myself and want to limit the…
Eric Stotch
  • 141
  • 4
  • 19
1
vote
1 answer

Clang sanitizers missing a read from uninitialized memory

I have the following code, that I am confident reads from garbage memory, but clang sanitizers do not complain. Is there something I can do to make them trigger or I should just accept this as limitation/bug? #include #include…
NoSenseEtAl
  • 28,205
  • 28
  • 128
  • 277
1
vote
0 answers

Boost undefined symbol issue while linking with static library with memory sanitizer

I am getting below error while building static library uhd-types and linking with boost libraries v1.74 with memory sanitizer flag -fsanitize=memory. [ 63%] Built target uhd-types [ 65%] Linking CXX executable ../../bin/unit_tests /usr/bin/ld:…
Pawan
  • 11
  • 1
1
vote
0 answers

cannot build memory sanitizer instrumented libc++ that link against only compile-rt (no libgcc)?

I want to use c++ memory sanitizer(msan) on a code repo with llvm toolchain (libc++, libunwind, compiler-rt, clang ...). so the first thing i need to do is to build msan-instrumented libc++. From MemorySanitizerLibcxxHowTo, i need to build libc++…
JohnNil
  • 33
  • 6
1
vote
1 answer

How to make MemorySanitizer not stop after one error

Clang's documentation says that "By default, MemorySanitizer exits on the first detected error." Does somebody know how to make MemorySanitizer not to stop on errors? The above sentence suggests that there is a way, but I do not find anything in the…
robert
  • 3,539
  • 3
  • 35
  • 56
1
2