diff options
author | lloyd <[email protected]> | 2010-07-07 19:00:53 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-07-07 19:00:53 +0000 |
commit | bb5892ce5140e21284bf736a85f45584c5b08b24 (patch) | |
tree | d5f0adc6eff034b4cb034fba85ed0611284ec5a1 /src/alloc/secmem.h | |
parent | 61734fa2696ff73c213d8e801a786e538258df8e (diff) |
Argh: SecureVector's constructor needs to behave differently
depending on if INITIAL_LEN is non-zero. Normal semantics are the
vector will change size based on whatever it is constructed with,
but that's bad in cases like
SecureVector<byte, 4> val(buffer, 3);
which in the past would be a 4 valued thing with 3 elements set
and one zero trailing. (This construct showed up in base64 and
possibly elsewhere). If INITIAL_LEN is set, use copy instead so
the length does not change.
C++0x cannot come soon enough.
Diffstat (limited to 'src/alloc/secmem.h')
-rw-r--r-- | src/alloc/secmem.h | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/alloc/secmem.h b/src/alloc/secmem.h index bc5a2499d..cd98bff46 100644 --- a/src/alloc/secmem.h +++ b/src/alloc/secmem.h @@ -380,7 +380,13 @@ class SecureVector : public MemoryRegion<T> * @param n the size of the array in */ SecureVector(const T in[], u32bit n) - { init(true); set(in, n); } + { + init(true, INITIAL_LEN); + if(INITIAL_LEN) + copy(in, n); + else + set(in, n); + } /** * Create a buffer with contents specified contents. @@ -388,7 +394,13 @@ class SecureVector : public MemoryRegion<T> * copied into the newly created buffer. */ SecureVector(const MemoryRegion<T>& in) - { init(true); set(in); } + { + init(true, INITIAL_LEN); + if(INITIAL_LEN) + copy(in); + else + set(in); + } /** * Create a buffer whose content is the concatenation of two other |