p-ranav / argparse

Argument Parser for Modern C++
MIT License
2.67k stars 244 forks source link

`-fsanitize=memory` MemorySanitizer: use-of-uninitialized-value #381

Open Arniiiii opened 2 hours ago

Arniiiii commented 2 hours ago

Right after I start my program with relatively simple setup of arguments:

==164058==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x55f0cc4185ce 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, std::_List_iterator<argparse::Argument>>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, std::_List_iterator<argparse::Argument>>>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, std::_List_iterator<argparse::Argument>>>>::_S_left(std::_Rb_tree_node_base*) /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/stl_tree.h:782:9
    #1 0x55f0cc6ce5a3 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, std::_List_iterator<argparse::Argument>>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, std::_List_iterator<argparse::Argument>>>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, std::_List_iterator<argparse::Argument>>>>::_M_lower_bound(std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, std::_List_iterator<argparse::Argument>>>*, std::_Rb_tree_node_base*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/stl_tree.h:1953:21
    #2 0x55f0cc6fd581 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, std::_List_iterator<argparse::Argument>>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, std::_List_iterator<argparse::Argument>>>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, std::_List_iterator<argparse::Argument>>>>::lower_bound(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/stl_tree.h:1271:16
    #3 0x55f0cc6f8a69 in std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::_List_iterator<argparse::Argument>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, std::_List_iterator<argparse::Argument>>>>::lower_bound(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/stl_map.h:1309:21
    #4 0x55f0cc6f85ff in std::pair<std::_Rb_tree_iterator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, std::_List_iterator<argparse::Argument>>>, bool> std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::_List_iterator<argparse::Argument>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, std::_List_iterator<argparse::Argument>>>>::insert_or_assign<std::_List_iterator<argparse::Argument>&>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::_List_iterator<argparse::Argument>&) /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/stl_map.h:970:19
    #5 0x55f0cc6f8487 in argparse::ArgumentParser::index_argument(std::_List_iterator<argparse::Argument>) /home/paxu/.cache/cpm/argparse/507556e7ed2f3c27e6f551d1b276204dfbbe35ca/include/argparse/argparse.hpp:2528:22
    #6 0x55f0cc40fac5 in argparse::Argument& argparse::ArgumentParser::add_argument<char const*, char const*>(char const*, char const*) /home/paxu/.cache/cpm/argparse/507556e7ed2f3c27e6f551d1b276204dfbbe35ca/include/argparse/argparse.hpp:1679:5
    #7 0x55f0cc40ea63 in argparse::ArgumentParser::ArgumentParser(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, argparse::default_arguments, bool, std::ostream&) /home/paxu/.cache/cpm/argparse/507556e7ed2f3c27e6f551d1b276204dfbbe35ca/include/argparse/argparse.hpp:1614:7
    #8 0x55f0cc40ced0 in main /home/paxu/data/code/project/standalone/source/main.cpp:135:28
    #9 0x7feab6e2a44f in __libc_start_call_main /usr/src/debug/sys-libs/glibc-2.39-r6/glibc-2.39/csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #10 0x7feab6e2a508 in __libc_start_main@GLIBC_2.2.5 /usr/src/debug/sys-libs/glibc-2.39-r6/glibc-2.39/csu/../csu/libc-start.c:360:3
    #11 0x55f0cc2cf004 in _start /usr/src/debug/sys-libs/glibc-2.39-r6/glibc-2.39/csu/../sysdeps/x86_64/start.S:115

SUMMARY: MemorySanitizer: use-of-uninitialized-value /home/paxu/.cache/cpm/argparse/507556e7ed2f3c27e6f551d1b276204dfbbe35ca/include/argparse/argparse.hpp:2528:22 in argparse::ArgumentParser::index_argument(std::_List_iterator<argparse::Argument>)
Exiting

I am using latest commit of argparse : 84c02050ea8bd1bf99de0a4943db40235e9fd5e7

wanjiadenghuo111 commented 2 hours ago

亲,来信已经收到!祝你快乐!

Arniiiii commented 1 hour ago

I guess minimal example is:

#include "argparse/argparse.hpp"

int main() {
    argparse::ArgumentParser program("test");
}
Arniiiii commented 1 hour ago

if -stdlib=libc++ :

==214958==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x56476164f01f in std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::__is_long[abi:ne200000]() const /usr/include/c++/v1/string:1883:5
    #1 0x5647616ae06e in std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::basic_string[abi:ne200000](std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&&)::'lambda'(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&)::operator()(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&) const /usr/include/c++/v1/string:1038:20
    #2 0x564761663a5a in std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::basic_string[abi:ne200000](std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&&) /usr/include/c++/v1/string:1037:16
    #3 0x564761656837 in argparse::ArgumentParser::ArgumentParser(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, argparse::default_arguments, bool, std::__1::basic_ostream<char, std::__1::char_traits<char>>&) /home/paxu/.cache/cpm/argparse/507556e7ed2f3c27e6f551d1b276204dfbbe35ca/include/argparse/argparse.hpp:1610:9
    #4 0x564761656440 in main /home/paxu/data/code/project/standalone/source/main.cpp:135:28
    #5 0x7f66d882a44f in __libc_start_call_main /usr/src/debug/sys-libs/glibc-2.39-r6/glibc-2.39/csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #6 0x7f66d882a508 in __libc_start_main@GLIBC_2.2.5 /usr/src/debug/sys-libs/glibc-2.39-r6/glibc-2.39/csu/../csu/libc-start.c:360:3
    #7 0x5647615af544 in _start /usr/src/debug/sys-libs/glibc-2.39-r6/glibc-2.39/csu/../sysdeps/x86_64/start.S:115

SUMMARY: MemorySanitizer: use-of-uninitialized-value /home/paxu/.cache/cpm/argparse/507556e7ed2f3c27e6f551d1b276204dfbbe35ca/include/argparse/argparse.hpp:1610:9 in argparse::ArgumentParser::ArgumentParser(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, argparse::default_arguments, bool, std::__1::basic_ostream<char, std::__1::char_traits<char>>&)
Exiting