This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch, libstdc++/64584, libstdc++/64585] Clear basic_regex after imbue and make assign exception tolerant


@@ -675,12 +681,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
	assign(const basic_string<_Ch_type, _Ch_typeraits, _Alloc>& __s,
	       flag_type __flags = ECMAScript)
	{
+	  auto __traits = _M_traits;
+	  auto __f = _M_flags;
	  _M_flags = __flags;
-	  _M_original_str.assign(__s.begin(), __s.end());
-	  auto __p = _M_original_str.c_str();
-	  _M_automaton = __detail::__compile_nfa(__p,
-						 __p + _M_original_str.size(),
-						 _M_traits, _M_flags);
+	  _M_traits = __traits;

What is this assignnment for?

+	  __try
+	    {
+	      _M_automaton = __detail::__compile_nfa(
+	        __s.data(), __s.data() + __s.size(), _M_traits, _M_flags);
+	      _M_original_str = __s;
+	    }
+	  __catch (...)
+	    {
+	      _M_traits = __traits;
+	      _M_flags = __f;
+	      __throw_exception_again;
+	    }
	  return *this;
	}

@@ -767,8 +786,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
      swap(basic_regex& __rhs)
      {
	std::swap(_M_flags, __rhs._M_flags);
-	std::swap(_M_original_str, __rhs._M_original_str);
-	this->imbue(__rhs.imbue(this->getloc()));
+	std::swap(_M_traits, __rhs._M_traits);
+	auto tmp = std::move(_M_original_str);

Please rename this to __tmp to avoid user-defined macros.

+	this->assign(__rhs._M_original_str, _M_flags);
+	__rhs.assign(tmp, __rhs._M_flags);
      }

#ifdef _GLIBCXX_DEBUG


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]