Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory sanitizer complaint #255

Closed
atn34 opened this issue Jul 23, 2019 · 1 comment
Closed

Memory sanitizer complaint #255

atn34 opened this issue Jul 23, 2019 · 1 comment

Comments

@atn34
Copy link

atn34 commented Jul 23, 2019

Description

Thanks for the awesome project!
I'm noticing memory sanitizer complaining about a usage of std::set.

Steps to reproduce

$ cat test.cc
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"

int factorial(int number) { return number <= 1 ? number : factorial(number - 1) * number; }

TEST_CASE("testing the factorial function") {
    CHECK(factorial(1) == 1);
    CHECK(factorial(2) == 2);
    CHECK(factorial(3) == 6);
    CHECK(factorial(10) == 3628800);
}

$ clang++ -fsanitize=memory test.cc -Idoctest && ./a.out
==24883==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x53a394 in std::_Rb_tree<std::pair<int, doctest::String>, std::pair<std::pair<int, doctest::String> const, doctest::IReporter* (*)(doctest::ContextOptions const&)>, std::_Select1st<std::pair<std::pair<int, doctest::String> const, doctest::IReporter* (*)(doctest::ContextOptions const&)> >, std::less<std::pair<int, doctest::String> >, std::allocator<std::pair<std::pair<int, doctest::String> const, doctest::IReporter* (*)(doctest::ContextOptions const&)> > >::_M_get_insert_unique_pos(std::pair<int, doctest::String> const&) (/home/anoyes/workspace/doctest-repro/doctest/a.out+0x53a394)
    #1 0x539e1b in std::pair<std::_Rb_tree_iterator<std::pair<std::pair<int, doctest::String> const, doctest::IReporter* (*)(doctest::ContextOptions const&)> >, bool> std::_Rb_tree<std::pair<int, doctest::String>, std::pair<std::pair<int, doctest::String> const, doctest::IReporter* (*)(doctest::ContextOptions const&)>, std::_Select1st<std::pair<std::pair<int, doctest::String> const, doctest::IReporter* (*)(doctest::ContextOptions const&)> >, std::less<std::pair<int, doctest::String> >, std::allocator<std::pair<std::pair<int, doctest::String> const, doctest::IReporter* (*)(doctest::ContextOptions const&)> > >::_M_insert_unique<std::pair<std::pair<int, doctest::String> const, doctest::IReporter* (*)(doctest::ContextOptions const&)> >(std::pair<std::pair<int, doctest::String> const, doctest::IReporter* (*)(doctest::ContextOptions const&)>&&) (/home/anoyes/workspace/doctest-repro/doctest/a.out+0x539e1b)
    #2 0x4f9cae in std::map<std::pair<int, doctest::String>, doctest::IReporter* (*)(doctest::ContextOptions const&), std::less<std::pair<int, doctest::String> >, std::allocator<std::pair<std::pair<int, doctest::String> const, doctest::IReporter* (*)(doctest::ContextOptions const&)> > >::insert(std::pair<std::pair<int, doctest::String> const, doctest::IReporter* (*)(doctest::ContextOptions const&)>&&) (/home/anoyes/workspace/doctest-repro/doctest/a.out+0x4f9cae)
    #3 0x4c78ef in doctest::detail::registerReporterImpl(char const*, int, doctest::IReporter* (*)(doctest::ContextOptions const&)) (/home/anoyes/workspace/doctest-repro/doctest/a.out+0x4c78ef)
    #4 0x4b1ac6 in int doctest::registerReporter<doctest::(anonymous namespace)::ConsoleReporter>(char const*, int) (/home/anoyes/workspace/doctest-repro/doctest/a.out+0x4b1ac6)
    #5 0x41d789 in __cxx_global_var_init.65 (/home/anoyes/workspace/doctest-repro/doctest/a.out+0x41d789)
    #6 0x41d9f7 in _GLOBAL__sub_I_test.cc (/home/anoyes/workspace/doctest-repro/doctest/a.out+0x41d9f7)
    #7 0x53cc2c in __libc_csu_init (/home/anoyes/workspace/doctest-repro/doctest/a.out+0x53cc2c)
    #8 0x7f638b665b27 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:266
    #9 0x41da29 in _start (/home/anoyes/workspace/doctest-repro/doctest/a.out+0x41da29)

SUMMARY: MemorySanitizer: use-of-uninitialized-value (/home/anoyes/workspace/doctest-repro/doctest/a.out+0x53a394) in std::_Rb_tree<std::pair<int, doctest::String>, std::pair<std::pair<int, doctest::String> const, doctest::IReporter* (*)(doctest::ContextOptions const&)>, std::_Select1st<std::pair<std::pair<int, doctest::String> const, doctest::IReporter* (*)(doctest::ContextOptions const&)> >, std::less<std::pair<int, doctest::String> >, std::allocator<std::pair<std::pair<int, doctest::String> const, doctest::IReporter* (*)(doctest::ContextOptions const&)> > >::_M_get_insert_unique_pos(std::pair<int, doctest::String> const&)
Exiting

Extra information

$ uname -a
Linux sasquatch 4.15.0-54-generic #58-Ubuntu SMP Mon Jun 24 10:55:24 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

$ git rev-parse HEAD
c250f8a698b070f5859c94739258a556a577bcd3

$ clang++ --version
clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

$ git bisect start HEAD 1.0.0
Bisecting: 421 revisions left to test after this (roughly 9 steps)
[ab8f7cfce7034ca3d9753cd338fb58e57c2a9d42] gcc 7 cannot work yet on travis...

$ git bisect run bash -c 'clang++ -fsanitize=memory test.cc -Idoctest || exit 125; ./a.out; exit $?'

...

8def6b040fd176f929e9ebc881810745e11e0a2d is the first bad commit
commit 8def6b040fd176f929e9ebc881810745e11e0a2d
Author: onqtam <[email protected]>
Date:   Fri Jun 10 21:28:08 2016 +0300

    removed custom implementations of vector and hashtable and now using std::vector and std::set

:040000 040000 3881a9649b386a8da9f9be7a669acc684ff66047 80f1546c91cdb31406a1f13bb37eba44ac82799f M      doctest
:040000 040000 ad0d1dd74ec472f7bcc62266ae2d1fb5223aaf31 ee2f54dc30e4a68c7fb8ffa48c2a47add90952b9 M      examples
:040000 040000 60beec22921f96ef5d674ed955afbbac261f3b14 18d53e1d99078e285f70568769473d2226660a6d M      scripts
bisect run success
@atn34
Copy link
Author

atn34 commented Jul 23, 2019

https://github.com/google/sanitizers/wiki/MemorySanitizerLibcxxHowTo

It looks like my problem is that I need to instrument libc++ with msan

@atn34 atn34 closed this as completed Jul 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant