@@ -24,8 +24,8 @@ std::string get_current_git_path()
2424// ->check(CLI::ExistingDirectory | CLI::NonexistentPath)
2525// ->default_val(std::filesystem::current_path());
2626
27- git_strarray_wrapper::git_strarray_wrapper (std::vector<std::string> m_patterns )
28- : m_patterns(std::move(m_patterns ))
27+ git_strarray_wrapper::git_strarray_wrapper (std::vector<std::string> patterns )
28+ : m_patterns(std::move(patterns ))
2929{
3030 init_str_array ();
3131}
@@ -34,23 +34,40 @@ git_strarray_wrapper::git_strarray_wrapper(git_strarray_wrapper&& rhs)
3434 : m_patterns(std::move(rhs.m_patterns))
3535{
3636 init_str_array ();
37+ rhs.reset_str_array ();
38+ }
39+
40+ git_strarray_wrapper& git_strarray_wrapper::operator =(git_strarray_wrapper&& rhs)
41+ {
42+ using std::swap;
43+ swap (m_patterns, rhs.m_patterns );
44+ swap (m_array.strings , rhs.m_array .strings );
45+ swap (m_array.count , rhs.m_array .count );
46+ return *this ;
3747}
3848
3949git_strarray_wrapper::~git_strarray_wrapper ()
4050{
41- delete[] m_array. strings ;
51+ reset_str_array () ;
4252}
4353
4454git_strarray_wrapper::operator git_strarray*()
4555{
4656 return &m_array;
4757}
4858
59+ void git_strarray_wrapper::reset_str_array ()
60+ {
61+ delete[] m_array.strings ;
62+ m_array={nullptr , 0 };
63+ }
64+
4965void git_strarray_wrapper::init_str_array ()
5066{
51- git_strarray array{new char *[m_patterns.size ()], m_patterns.size ()};
67+ m_array.strings = new char *[m_patterns.size ()];
68+ m_array.count = m_patterns.size ();
5269 for (size_t i=0 ; i<m_patterns.size (); ++i)
5370 {
54- array .strings [i] = const_cast <char *>(m_patterns[i].c_str ());
71+ m_array .strings [i] = const_cast <char *>(m_patterns[i].c_str ());
5572 }
5673}
0 commit comments