summaryrefslogtreecommitdiff
path: root/src/include/rc_string.hpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2018-11-04 20:28:32 +0800
committerJohn Hodge <tpg@ucc.asn.au>2018-11-04 20:28:32 +0800
commit1726886913173c2828e962d7c5d384e3915d0ae3 (patch)
treec3864d5b5297cd273db968e329953861388b93fa /src/include/rc_string.hpp
parent17be046b4ea045118664d1420cf3263770921a4f (diff)
downloadmrust-1726886913173c2828e962d7c5d384e3915d0ae3.tar.gz
All - Cleaning up some memory leaks
Diffstat (limited to 'src/include/rc_string.hpp')
-rw-r--r--src/include/rc_string.hpp37
1 files changed, 12 insertions, 25 deletions
diff --git a/src/include/rc_string.hpp b/src/include/rc_string.hpp
index eec47d80..914228c6 100644
--- a/src/include/rc_string.hpp
+++ b/src/include/rc_string.hpp
@@ -29,12 +29,7 @@ public:
{
}
- RcString(const RcString& x):
- m_ptr(x.m_ptr),
- m_len(x.m_len)
- {
- if( m_ptr ) *m_ptr += 1;
- }
+ RcString(const RcString& x);
RcString(RcString&& x):
m_ptr(x.m_ptr),
m_len(x.m_len)
@@ -47,36 +42,28 @@ public:
RcString& operator=(const RcString& x)
{
- if( &x != this )
- {
- this->~RcString();
- m_ptr = x.m_ptr;
- m_len = x.m_len;
- if( m_ptr ) *m_ptr += 1;
- }
+ if( !(&x != this) ) throw "";
+
+ this->~RcString();
+ new (this) RcString(x);
+
return *this;
}
RcString& operator=(RcString&& x)
{
- if( &x != this )
- {
- this->~RcString();
- m_ptr = x.m_ptr;
- m_len = x.m_len;
- x.m_ptr = nullptr;
- x.m_len = 0;
- }
+ if( !(&x != this) ) throw "";
+
+ this->~RcString();
+ new (this) RcString( ::std::move(x) );
return *this;
}
const char* c_str() const {
- if( m_len > 0 )
- {
+ if( m_len > 0 ) {
return reinterpret_cast<const char*>(m_ptr + 1);
}
- else
- {
+ else {
return "";
}
}