Questions tagged [msan]

Memory sanitizer (msan) is a fast memory checker for Clang and GCC. Various computations will be instrumented to detect memory issues at runtime.

Memory sanitizer (msan) is a fast memory checker for C and C++ programs and enabled at compile time (but the checks are performed at runtime). It is available since Clang 3.3.

See also:

16 questions
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
16
votes
1 answer

clang memory sanitizer; how to make it print source line numbers

I'm compiling my program with clang++ -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -g -O0 and when I run it, the output is: matiu@matiu-laptop:~/projects/json++11/build$ ./tests .......==10534== WARNING:…
matiu
  • 7,469
  • 4
  • 44
  • 48
8
votes
3 answers

Memory Sanitizer

I am playing around with Memory Sanitizer with Clang 3.7.0 on Ubuntu 14.04. The following code does work perfectly: #include int main() { double ans; printf("Hello World: %f\n", ans); return 0; } when compiled with clang++ -g -O1…
InsideLoop
  • 6,063
  • 2
  • 28
  • 55
6
votes
2 answers

Memory sanitizer reports use-of-uninitialized-value in global object construction

I get use-of-uninitialized-value warning while executing the following program compiled with clang++-9 -fsanitize=memory: #include class msan_test { std::map m_map; public: msan_test() { m_map.insert(std::make_pair(1,…
6
votes
1 answer

Building libc++ with MemorySanitizer instrumentation fails due to MemorySanitizer warning

I'm trying to build libc++ with MemorySanitizer instrumentation so that I can build my own projects with MemorySanitizer. I am using Clang 8.01 on Ubuntu 16.04. I followed the instructions given here, but the build initially failed with a linker…
Daniel
  • 376
  • 2
  • 7
6
votes
2 answers

Unable to reproduce memory sanitization results from the project's example project

I'm getting exactly the same results from centos7, clang-3.6.1 built from source using a fedora rpm specfile. Ubuntu 14.04, clang-3.4 Using the instructions from the wiki here https://github.com/google/sanitizers/wiki/MemorySanitizerLibcxxHowTo as…
Hal
  • 1,061
  • 7
  • 20
5
votes
1 answer

How to determine when -fsanitize=memory is in use?

I want to clear a false positive on FD_ZERO and FD_SET when the memory sanitizer is in use. Clearing it is somewhat easy: #include ... __msan_unpoison(&readfds, sizeof(readfds)); __msan_unpoison(&writefds,…
jww
  • 97,681
  • 90
  • 411
  • 885
4
votes
0 answers

Why does clang MemorySanitizer produce error in fstream open?

I am trying to integrate Memory Sanitizer into my project. And following code raise an use-of-uninitialized-value error: #include int main () { std::ifstream ifs; ifs.open ("test.txt", std::ifstream::in); char c = ifs.get(); //…
2
votes
0 answers

Memory sanitizer false positive on centos 7 but not on other platform

my test code is the following: #include #include int main() { std::string mylongstring("This is a test string"); std::cout << mylongstring << std::endl; } and I compile with the latest clang, using a GCC 7.2…
hassec
  • 686
  • 4
  • 18
2
votes
1 answer

Using -fsanitize=memory with clang on linux with libstdc++

With the system supplied libstdc++ the clang memory sanitizer is basically unusable due to false positives - eg the code below fails. #include #include int main(int argc, char **argv) { double foo = 1.2; std::ofstream…
Hal
  • 1,061
  • 7
  • 20
1
vote
0 answers

Uninitialized memory bug using the zip.h library in WSL Ubuntu 22.04

I was writing some code on C that opens an encrypted zip file and tries to read its contents. The program works well, but when I was reviewing the code with some tools to make sure there were no leaks or issues, I found a strange issue when…
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
0
votes
0 answers

Is there anyway to debug "go test -msan" command?

I've recently looking for any way to debug "go test -msan". I am facing with a core-dump (Segmentation Fault) when pipeline executing this command and I need more detailed background informations about what is going on. So, I need to a way to debug…
alimertkoc
  • 13
  • 2
0
votes
0 answers

SDL2 SDL_Init function triggers memory sanitizer error (relying on uninitialized data)

clang -g -fsanitize=memory -Wconversion -Wsign-conversion -Wextra -Wall -Werror -pedantic -I/usr/include/SDL2 -lSDL2_image -lSDL2_gfx -lSDL2 -lSDL2_ttf -lc -lm ./deps/**/*.c ./src/*.c ./src/**/*.c -o ./bin/output ./bin/output Uninitialized bytes…
user7847084
0
votes
1 answer

clang memory sanitizer (linux) does not report errors

I'm attempting to produce clang memory sanitizer errors on a linux platform with a toy program. I haven't been able to produce any errors with what I believe is a correct platform / compilation / execution. A simple description of the…
manabear
  • 431
  • 3
  • 6