ramosian-glider / memory-sanitizer

Automatically exported from code.google.com/p/memory-sanitizer
0 stars 0 forks source link

False positive with std::string and strlen #38

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Here is a sample program:

#include<string>
#include<cstring>

int main(int argc, char **argv) {
  std::string a;
  a = "abc";
  strlen(a.c_str());
  return 0;
}

compile it with this exact command:

clang++ -std=c++11 -fsanitize=memory -g -O0 -fno-omit-frame-pointer 
clangstrtest.cpp -o clangstrtest

When run, I get this (on Ubuntu 13/10 amd64):

UMR in __interceptor_strlen at offset 3 inside [0x60400000eff8, +4) 

This issue is _not_ reported if you use any kind of optimization, even -O1.

Using latest clang trunk as of yesterday.

Original issue reported on code.google.com by jpakk...@gmail.com on 22 Nov 2013 at 8:30

GoogleCodeExporter commented 9 years ago
You are using uninstrumented libstdc++, and MSan does not see memory writes in 
it.
There are two options:
1. Build libstdc++, or (recommended) libc++ with MSan. But if your program is 
using other third party libraries, you have the same issue with them.
2. Use msandr.

As for -O1, strlen call is dead code and gets optimized out.

Original comment by euge...@google.com on 3 Dec 2013 at 2:23

GoogleCodeExporter commented 9 years ago
Adding Project:MemorySanitizer as part of GitHub migration.

Original comment by gli...@google.com on 30 Jul 2015 at 9:22