Fixed SecBlock append when "this == t" (Issue 92)
parent
217ad8d721
commit
8b0f29a4f2
28
secblock.h
28
secblock.h
|
|
@ -566,15 +566,23 @@ public:
|
||||||
//! \details Internally, this SecBlock calls Grow and then appends t.
|
//! \details Internally, this SecBlock calls Grow and then appends t.
|
||||||
SecBlock<T, A>& operator+=(const SecBlock<T, A> &t)
|
SecBlock<T, A>& operator+=(const SecBlock<T, A> &t)
|
||||||
{
|
{
|
||||||
assert((!t.m_ptr && !t.m_size) || (t.m_ptr && t.m_ptr.m_size));
|
assert((!t.m_ptr && !t.m_size) || (t.m_ptr && t.m_size));
|
||||||
|
|
||||||
if(t.size)
|
if(t.m_size)
|
||||||
{
|
{
|
||||||
size_type oldSize = m_size;
|
if(this != &t) // s += t
|
||||||
Grow(m_size+t.m_size);
|
{
|
||||||
|
const size_type oldSize = m_size;
|
||||||
if (m_ptr && t.m_ptr)
|
Grow(m_size+t.m_size);
|
||||||
{memcpy_s(m_ptr+oldSize, (m_size-oldSize)*sizeof(T), t.m_ptr, t.m_size*sizeof(T));}
|
memcpy_s(m_ptr+oldSize, (m_size-oldSize)*sizeof(T), t.m_ptr, t.m_size*sizeof(T));
|
||||||
|
}
|
||||||
|
else // t += t
|
||||||
|
{
|
||||||
|
SecBlock result(m_size+t.m_size);
|
||||||
|
if(m_size) {memcpy_s(result.m_ptr, result.m_size, m_ptr, m_size);}
|
||||||
|
memcpy_s(result.m_ptr+m_size, (result.m_size-m_size)*sizeof(T), t.m_ptr, t.m_size*sizeof(T));
|
||||||
|
swap(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
@ -586,12 +594,12 @@ public:
|
||||||
SecBlock<T, A> operator+(const SecBlock<T, A> &t)
|
SecBlock<T, A> operator+(const SecBlock<T, A> &t)
|
||||||
{
|
{
|
||||||
assert((!m_ptr && !m_size) || (m_ptr && m_size));
|
assert((!m_ptr && !m_size) || (m_ptr && m_size));
|
||||||
assert((!t.m_ptr && !t.m_size) || (t.m_ptr && t.m_ptr.m_size));
|
assert((!t.m_ptr && !t.m_size) || (t.m_ptr && t.m_size));
|
||||||
if(!t.size) return SecBlock(*this);
|
if(!t.size) return SecBlock(*this);
|
||||||
|
|
||||||
SecBlock<T, A> result(m_size+t.m_size);
|
SecBlock<T, A> result(m_size+t.m_size);
|
||||||
memcpy_s(result.m_ptr, result.m_size*sizeof(T), m_ptr, m_size*sizeof(T));
|
if(m_size) {memcpy_s(result.m_ptr, result.m_size*sizeof(T), m_ptr, m_size*sizeof(T));}
|
||||||
memcpy_s(result.m_ptr+m_size, (t.m_size-m_size)*sizeof(T), t.m_ptr, t.m_size*sizeof(T));
|
memcpy_s(result.m_ptr+m_size, (result.m_size-m_size)*sizeof(T), t.m_ptr, t.m_size*sizeof(T));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue