summaryrefslogtreecommitdiff
path: root/secblock.h
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2021-04-09 04:55:28 -0400
committerJeffrey Walton <noloader@gmail.com>2021-04-09 04:55:28 -0400
commitfcf1f56833b89ad1ae38ea2de06f6b939b186174 (patch)
treed9bb73533477aa72183156e9879d9ea1a7a17890 /secblock.h
parentf1f23c083a762ab19b351519f629fe46164cad12 (diff)
downloadcryptopp-git-fcf1f56833b89ad1ae38ea2de06f6b939b186174.tar.gz
Update SecBlock Assign and Append
0-size arrays need to be assigned, too.
Diffstat (limited to 'secblock.h')
-rw-r--r--secblock.h36
1 files changed, 22 insertions, 14 deletions
diff --git a/secblock.h b/secblock.h
index a899cea9..425617c7 100644
--- a/secblock.h
+++ b/secblock.h
@@ -891,12 +891,17 @@ public:
/// \since Crypto++ 2.0
void Assign(const T *ptr, size_type len)
{
- // ptr is unknown. It could be same array or different array.
- // It could be same array at different offset so m_ptr!=ptr.
- SecBlock<T, A> t(len);
- if (t.m_ptr && ptr) // GCC analyzer warning
- memcpy_s(t.m_ptr, t.m_size*sizeof(T), ptr, len*sizeof(T));
- std::swap(*this, t);
+ if (len)
+ {
+ // ptr is unknown. It could be same array or different array.
+ // It could be same array at different offset so m_ptr!=ptr.
+ SecBlock<T, A> t(len);
+ if (t.m_ptr && ptr) // GCC analyzer warning
+ memcpy_s(t.m_ptr, t.m_size*sizeof(T), ptr, len*sizeof(T));
+ std::swap(*this, t);
+ }
+ else
+ New(0);
m_mark = ELEMS_MAX;
}
@@ -950,14 +955,17 @@ public:
if (ELEMS_MAX - m_size < len)
throw InvalidArgument("Append: buffer overflow");
- // ptr is unknown. It could be same array or different array.
- // It could be same array at different offset so m_ptr!=ptr.
- SecBlock<T, A> t(m_size+len);
- if (t.m_ptr && m_ptr) // GCC analyzer warning
- memcpy_s(t.m_ptr, t.m_size*sizeof(T), m_ptr, m_size*sizeof(T));
- if (t.m_ptr && ptr) // GCC analyzer warning
- memcpy_s(t.m_ptr+m_size, (t.m_size-m_size)*sizeof(T), ptr, len*sizeof(T));
- std::swap(*this, t);
+ if (len)
+ {
+ // ptr is unknown. It could be same array or different array.
+ // It could be same array at different offset so m_ptr!=ptr.
+ SecBlock<T, A> t(m_size+len);
+ if (t.m_ptr && m_ptr) // GCC analyzer warning
+ memcpy_s(t.m_ptr, t.m_size*sizeof(T), m_ptr, m_size*sizeof(T));
+ if (t.m_ptr && ptr) // GCC analyzer warning
+ memcpy_s(t.m_ptr+m_size, (t.m_size-m_size)*sizeof(T), ptr, len*sizeof(T));
+ std::swap(*this, t);
+ }
m_mark = ELEMS_MAX;
}