Revert "Fixed SecBlock append when "this == t" (Issue 92)". It was an incomplete remediation.
This reverts commit 8b0f29a4f2.
pull/95/head
parent
8b0f29a4f2
commit
985172421a
28
secblock.h
28
secblock.h
|
|
@ -566,23 +566,15 @@ public:
|
|||
//! \details Internally, this SecBlock calls Grow and then appends t.
|
||||
SecBlock<T, A>& operator+=(const SecBlock<T, A> &t)
|
||||
{
|
||||
assert((!t.m_ptr && !t.m_size) || (t.m_ptr && t.m_size));
|
||||
assert((!t.m_ptr && !t.m_size) || (t.m_ptr && t.m_ptr.m_size));
|
||||
|
||||
if(t.m_size)
|
||||
if(t.size)
|
||||
{
|
||||
if(this != &t) // s += t
|
||||
{
|
||||
const size_type oldSize = m_size;
|
||||
Grow(m_size+t.m_size);
|
||||
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);
|
||||
}
|
||||
size_type oldSize = m_size;
|
||||
Grow(m_size+t.m_size);
|
||||
|
||||
if (m_ptr && t.m_ptr)
|
||||
{memcpy_s(m_ptr+oldSize, (m_size-oldSize)*sizeof(T), t.m_ptr, t.m_size*sizeof(T));}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -594,12 +586,12 @@ public:
|
|||
SecBlock<T, A> operator+(const SecBlock<T, A> &t)
|
||||
{
|
||||
assert((!m_ptr && !m_size) || (m_ptr && m_size));
|
||||
assert((!t.m_ptr && !t.m_size) || (t.m_ptr && t.m_size));
|
||||
assert((!t.m_ptr && !t.m_size) || (t.m_ptr && t.m_ptr.m_size));
|
||||
if(!t.size) return SecBlock(*this);
|
||||
|
||||
SecBlock<T, A> result(m_size+t.m_size);
|
||||
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, (result.m_size-m_size)*sizeof(T), t.m_ptr, t.m_size*sizeof(T));
|
||||
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));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue