ramosian-glider / memory-sanitizer

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

Possible false positive when memory sanitizing GoogleTest #70

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Get https://chromium.googlesource.com/external/googletest.git
2. Create simple main.cpp that looks something like;
  #include "gtest/gtest.h"
  GTEST_API_ int main(int argc, char** argv) {
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
  }
3. At global initialization time, memory sanitizer complains at line 1951 of 
gtest.cc.

What is the expected output? What do you see instead?
I suspect I should see no complaint here - but again could be wrong.

What version of the product are you using? On what operating system?
Using LLVM 3.5 release of clang, with -fsanitize=memory

Please provide any additional information below.
This is the function in the file;
  std::string StringStreamToString(::std::stringstream* ss) {
    const ::std::string& str = ss->str();
    const char* const start = str.c_str();
    const char* const end = start + str.length();

    std::string result;
    result.reserve(2 * (end - start));
    for (const char* ch = start; ch != end; ++ch) {
      if (*ch == '\0') {
        result += "\\0";  // Replaces NUL with "\\0";
      } else {
        result += *ch;
      }
    }

    return result;
  }

And line 1951 is 'if (*ch == '\0') {'

And the error is;
  ==16829== WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7f2a599d896d in testing::internal::StringStreamToString(std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >*) /home/jenkins/workspace/llvm/tools/clang/tools/extra/tests/../external/googletest/src/gtest.cc:1951
    #1 0x7f2a599d85b0 in testing::Message::GetString() const /home/jenkins/workspace/llvm/tools/clang/tools/extra/tests/../external/googletest/src/gtest.cc:943
    #2 0x7f2a59a35e43 in testing::internal::FlagToEnvVar(char const*) /home/jenkins/workspace/llvm/tools/clang/tools/extra/tests/../external/googletest/src/gtest-port.cc:1090
    #3 0x7f2a599ca9df in testing::internal::BoolFromGTestEnv(char const*, bool) /home/jenkins/workspace/llvm/tools/clang/tools/extra/tests/../external/googletest/src/gtest-port.cc:1146

I am super happy to be proved wrong about this, but I can't easily how this is 
a genuine memory error!

Original issue reported on code.google.com by Shere...@gmail.com on 17 Oct 2014 at 4:05

GoogleCodeExporter commented 9 years ago
did you build msna-instrumented libstdc++ or libc++? 

Original comment by konstant...@gmail.com on 17 Oct 2014 at 4:09

GoogleCodeExporter commented 9 years ago
Yes, it looks like you did not build an MSan-instrumented libc++ or libstdc++. 
MSan requires that all libraries in the process (with the exception of libc) 
are instrumented.

Building with -fsanitize-memory-track-origins=2 should make it clear.

Original comment by euge...@google.com on 17 Oct 2014 at 5:13

GoogleCodeExporter commented 9 years ago
Aha! Ok phew - I was using system libstdc++ without realising!

Thanks again for your help - happy for the issue to be closed!

Original comment by Shere...@gmail.com on 17 Oct 2014 at 10:17

GoogleCodeExporter commented 9 years ago

Original comment by euge...@google.com on 20 Oct 2014 at 3:03

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