summaryrefslogtreecommitdiff
path: root/datatest.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2021-03-21 17:14:44 -0400
committerJeffrey Walton <noloader@gmail.com>2021-03-21 17:14:44 -0400
commit9d0cb653eced9a4c12acadd0dd3c8e581d0ddf23 (patch)
tree2e4c8f3569608c32f28a04392c1f6029776e7831 /datatest.cpp
parentce8d243bf1e79078c8fde1a107c0a99ae2ebbd79 (diff)
downloadcryptopp-git-9d0cb653eced9a4c12acadd0dd3c8e581d0ddf23.tar.gz
Update datatest.cpp to use temp string
Diffstat (limited to 'datatest.cpp')
-rw-r--r--datatest.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/datatest.cpp b/datatest.cpp
index 5560711f..76cd5583 100644
--- a/datatest.cpp
+++ b/datatest.cpp
@@ -52,8 +52,11 @@ const std::string testDataFilename = "cryptest.dat";
// For istream.fail() see https://stackoverflow.com/q/34395801/608639.
bool Readline(std::istream& stream, std::string& line)
{
+ // Ensure old data is cleared
line.clear();
- line.reserve(64);
+
+ std::string temp;
+ temp.resize(64);
while (!stream.fail())
{
@@ -73,16 +76,18 @@ bool Readline(std::istream& stream, std::string& line)
// Let string class manage its own capacity.
// The string will grow as needed.
- line.push_back(static_cast<char>(ch));
+ temp.push_back(static_cast<char>(ch));
}
#if defined(CRYPTOPP_CXX11)
- line.shrink_to_fit();
+ temp.shrink_to_fit();
#else
// Non-binding shrink to fit
- line.reserve(0);
+ temp.reserve(0);
#endif
+ std::swap(line, temp);
+
return !stream.fail();
}
@@ -1314,7 +1319,7 @@ void TestDataFile(std::string filename, const NameValuePairs &overrideParameters
// value is used in subsequent tests, and it could cause a self test
// failure in the next test. The behavior surfaced under Kalyna and
// Threefish. The Kalyna test vectors use NO_PADDING for all tests except
- // one. Threefish occasionally use a Tweak.
+ // one. Threefish occasionally uses a Tweak.
//
// Unlatch BlockPadding, BlockSize and Tweak now, after the test has been
// run. Also note we only unlatch from 'TestData v'. If overrideParameters