catchorg / Catch2

A modern, C++-native, test framework for unit-tests, TDD and BDD - using C++14, C++17 and later (C++11 support is in v2.x branch, and C++03 on the Catch1.x branch)
https://discord.gg/4CWS9zD
Boost Software License 1.0
18.78k stars 3.06k forks source link

LLVM's memory sanitizer caught use of uninitialized value #2939

Open ImmanuelHaffner opened 3 days ago

ImmanuelHaffner commented 3 days ago

Describe the bug I build my code with Clang and LLVM's memory sanitizer. When running the tests, msan reports a use of an uninitialized value in the Catch2 code part.

Expected behavior No use of uninitialized value. Perhaps it is a false positive, in which case it would be nice if you annotated the respective code segment accordingly.

Reproduction steps

I have a custom main():

#include <catch2/catch_session.hpp>
#include <clocale>
#include <iostream>

int main(int argc, char* argv[])
{
    std::setlocale(LC_ALL, "en_US.UTF-8");
    std::locale::global(std::locale("en_US.UTF-8"));
    std::cout.imbue(std::locale());
    int result = Catch::Session().run( argc, argv );
    return result;
}

I compile with -stdlib=libc++ -lc++abi -fsanitize=memory -fsanitize-link-c++-runtime.

Platform information:

Additional information MSan trace

==6381==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x555555a0af26 in std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::pair<std::__cxx11::basic_string<char, std::char
_traits<char>, std::allocator<char>> const, Catch::Detail::unique_ptr<Catch::IReporterFactory>>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_trait
s<char>, std::allocator<char>> const, Catch::Detail::unique_ptr<Catch::IReporterFactory>>>, Catch::Detail::CaseInsensitiveLess, std::allocator<std::pair<std::__cxx11::basi
c_string<char, std::char_traits<char>, std::allocator<char>> const, Catch::Detail::unique_ptr<Catch::IReporterFactory>>>>::_S_right(std::_Rb_tree_node_base*) /usr/bin/../l
ib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/stl_tree.h:786:9
    #1 0x555555a0dec1 in std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::pair<std::__cxx11::basic_string<char, std::char
_traits<char>, std::allocator<char>> const, Catch::Detail::unique_ptr<Catch::IReporterFactory>>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_trait
s<char>, std::allocator<char>> const, Catch::Detail::unique_ptr<Catch::IReporterFactory>>>, Catch::Detail::CaseInsensitiveLess, std::allocator<std::pair<std::__cxx11::basi
c_string<char, std::char_traits<char>, std::allocator<char>> const, Catch::Detail::unique_ptr<Catch::IReporterFactory>>>>::_M_lower_bound(std::_Rb_tree_node<std::pair<std:
:__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, Catch::Detail::unique_ptr<Catch::IReporterFactory>>>*, std::_Rb_tree_node_base*, std::__c
xx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/stl_tre
e.h:1951:10
    #2 0x555555a0da34 in std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::pair<std::__cxx11::basic_string<char, std::char
_traits<char>, std::allocator<char>> const, Catch::Detail::unique_ptr<Catch::IReporterFactory>>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_trait
s<char>, std::allocator<char>> const, Catch::Detail::unique_ptr<Catch::IReporterFactory>>>, Catch::Detail::CaseInsensitiveLess, std::allocator<std::pair<std::__cxx11::basi
c_string<char, std::char_traits<char>, std::allocator<char>> const, Catch::Detail::unique_ptr<Catch::IReporterFactory>>>>::lower_bound(std::__cxx11::basic_string<char, std
::char_traits<char>, std::allocator<char>> const&) /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/stl_tree.h:1267:16
    #3 0x555555a0ca62 in std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, Catch::Detail::unique_ptr<Catch::IReporterFactory>, Catch
::Detail::CaseInsensitiveLess, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, Catch::Detail::unique_ptr<Cat
ch::IReporterFactory>>>>::lower_bound(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/14.2
.1/../../../../include/c++/14.2.1/bits/stl_map.h:1308:21
    #4 0x555555a01929 in std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, Catch::Detail::unique_ptr<Catch::IReporterFactory>, Catch
::Detail::CaseInsensitiveLess, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, Catch::Detail::unique_ptr<Cat
ch::IReporterFactory>>>>::operator[](std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&&) /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../
../../../include/c++/14.2.1/bits/stl_map.h:529:17
    #5 0x5555559feec6 in Catch::ReporterRegistry::ReporterRegistry() /home/immanuel/Documents/mutable-org/mutable-db/build/DebugMSan/src/catch2/internal/catch_reporter_reg
istry.cpp:37:9
    #6 0x555555cd046d in Catch::(anonymous namespace)::RegistryHub::RegistryHub() /home/immanuel/Documents/mutable-org/mutable-db/build/DebugMSan/src/catch2/catch_registry
_hub.cpp:35:13
    #7 0x555555cd0150 in Catch::Singleton<Catch::(anonymous namespace)::RegistryHub, Catch::IRegistryHub, Catch::IMutableRegistryHub>::Singleton() /home/immanuel/Documents
/mutable-org/mutable-db/build/DebugMSan/src/catch2/../catch2/internal/catch_singletons.hpp:23:11
    #8 0x555555ccff09 in Catch::Singleton<Catch::(anonymous namespace)::RegistryHub, Catch::IRegistryHub, Catch::IMutableRegistryHub>::getInternal() /home/immanuel/Documen
ts/mutable-org/mutable-db/build/DebugMSan/src/catch2/../catch2/internal/catch_singletons.hpp:28:34
    #9 0x555555ccfce8 in Catch::Singleton<Catch::(anonymous namespace)::RegistryHub, Catch::IRegistryHub, Catch::IMutableRegistryHub>::getMutable() /home/immanuel/Document
s/mutable-org/mutable-db/build/DebugMSan/src/catch2/../catch2/internal/catch_singletons.hpp:39:21
    #10 0x555555ccfcd8 in Catch::getMutableRegistryHub() /home/immanuel/Documents/mutable-org/mutable-db/build/DebugMSan/src/catch2/catch_registry_hub.cpp:95:16
    #11 0x555555ad41b0 in Catch::AutoReg::AutoReg(Catch::Detail::unique_ptr<Catch::ITestInvoker>, Catch::SourceLineInfo const&, Catch::StringRef, Catch::NameAndTags const&
) /home/immanuel/Documents/mutable-org/mutable-db/build/DebugMSan/src/catch2/internal/catch_test_registry.cpp:71:13
    #12 0x5555555a91c3 in __cxx_global_var_init /home/immanuel/Documents/mutable-org/mutable-db/test/unittests/parse/LexerTest.cpp:19:1
    #13 0x5555555a9788 in _GLOBAL__sub_I_LexerTest.cpp /home/immanuel/Documents/mutable-org/mutable-db/test/unittests/parse/LexerTest.cpp
    #14 0x7ffff7a06f43 in __libc_start_main (/usr/lib/libc.so.6+0x25f43) (BuildId: 98b3d8e0b8c534c769cb871c438b4f8f3a8e4bf3)
    #15 0x5555555af1a4 in _start (/home/immanuel/Documents/mutable-org/mutable-db/build/DebugMSan/bin/run_tests+0x5b1a4) (BuildId: a83c5acd676678229971e14582b2369c6240f2cc
)

SUMMARY: MemorySanitizer: use-of-uninitialized-value /home/immanuel/Documents/mutable-org/mutable-db/build/DebugMSan/src/catch2/internal/catch_reporter_registry.cpp:37:9 i
n Catch::ReporterRegistry::ReporterRegistry()
Exiting
horenmar commented 1 day ago

Have you properly instrumented all external code, including your standard library?