diff options
author | Riccardo Spagni <ric@spagni.net> | 2017-12-19 22:03:07 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2017-12-19 22:03:07 +0200 |
commit | 7a9a4a666986589dff679d086b377a9dfaa99d69 (patch) | |
tree | 3da169933fb461079dd0169907e3504126f0c126 /contrib | |
parent | Merge pull request #2134 (diff) | |
parent | wipeable_string: move a wipe from reserve to grow (diff) | |
download | monero-7a9a4a666986589dff679d086b377a9dfaa99d69.tar.xz |
Merge pull request #2961
6c94516f wipeable_string: move a wipe from reserve to grow (moneromooo-monero)
5f801b6a wipeable_string: ignore reserve size less than actual size (moneromooo-monero)
9ec44a2b wipeable_string: fix clear and push_back (moneromooo-monero)
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/epee/src/wipeable_string.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/contrib/epee/src/wipeable_string.cpp b/contrib/epee/src/wipeable_string.cpp index 75191df71..894c47bbd 100644 --- a/contrib/epee/src/wipeable_string.cpp +++ b/contrib/epee/src/wipeable_string.cpp @@ -85,11 +85,15 @@ void wipeable_string::wipe() void wipeable_string::grow(size_t sz, size_t reserved) { CHECK_AND_ASSERT_THROW_MES(wipefunc, "wipefunc is not set"); - if (reserved == 0) + if (reserved < sz) reserved = sz; - CHECK_AND_ASSERT_THROW_MES(reserved >= sz, "reserved < sz"); if (reserved <= buffer.capacity()) + { + if (sz < buffer.size()) + wipefunc(buffer.data() + sz, buffer.size() - sz); + buffer.resize(sz); return; + } size_t old_sz = buffer.size(); std::unique_ptr<char[]> tmp{new char[old_sz]}; memcpy(tmp.get(), buffer.data(), old_sz * sizeof(char)); @@ -103,7 +107,7 @@ void wipeable_string::grow(size_t sz, size_t reserved) void wipeable_string::push_back(char c) { grow(size() + 1); - buffer.push_back(c); + buffer.back() = c; } void wipeable_string::pop_back() @@ -113,9 +117,6 @@ void wipeable_string::pop_back() void wipeable_string::resize(size_t sz) { - CHECK_AND_ASSERT_THROW_MES(wipefunc, "wipefunc is not set"); - if (sz < buffer.size()) - wipefunc(buffer.data() + sz, buffer.size() - sz); grow(sz); } |