wipeable_string: fix clear and push_back

This commit is contained in:
moneromooo-monero 2017-12-19 11:55:45 +00:00
parent 1cc7451130
commit 9ec44a2b06
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3

View file

@ -89,7 +89,10 @@ void wipeable_string::grow(size_t sz, size_t reserved)
reserved = sz; reserved = sz;
CHECK_AND_ASSERT_THROW_MES(reserved >= sz, "reserved < sz"); CHECK_AND_ASSERT_THROW_MES(reserved >= sz, "reserved < sz");
if (reserved <= buffer.capacity()) if (reserved <= buffer.capacity())
{
buffer.resize(sz);
return; return;
}
size_t old_sz = buffer.size(); size_t old_sz = buffer.size();
std::unique_ptr<char[]> tmp{new char[old_sz]}; std::unique_ptr<char[]> tmp{new char[old_sz]};
memcpy(tmp.get(), buffer.data(), old_sz * sizeof(char)); memcpy(tmp.get(), buffer.data(), old_sz * sizeof(char));
@ -103,7 +106,7 @@ void wipeable_string::grow(size_t sz, size_t reserved)
void wipeable_string::push_back(char c) void wipeable_string::push_back(char c)
{ {
grow(size() + 1); grow(size() + 1);
buffer.push_back(c); buffer.back() = c;
} }
void wipeable_string::pop_back() void wipeable_string::pop_back()