diff options
author | Jeffrey Walton <noloader@gmail.com> | 2020-09-20 06:08:15 -0400 |
---|---|---|
committer | Jeffrey Walton <noloader@gmail.com> | 2020-09-20 06:08:15 -0400 |
commit | c280ccd33b3d85dbd2e5a3edd4fbeeded65a2288 (patch) | |
tree | 6c79eaae40eea027a47cb745e0083c062da4845e /files.cpp | |
parent | 0763b9984c6713d3d00de93de9854e58564493ea (diff) | |
download | cryptopp-git-c280ccd33b3d85dbd2e5a3edd4fbeeded65a2288.tar.gz |
Clear stream errors in FileStore::MaxRetrievable (GH #968)
Diffstat (limited to 'files.cpp')
-rw-r--r-- | files.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -65,10 +65,19 @@ lword FileStore::MaxRetrievable() const if (!m_stream)
return 0;
+ // Clear error bits due to seekg(). Also see
+ // https://github.com/weidai11/cryptopp/pull/968
std::streampos current = m_stream->tellg();
std::streampos end = m_stream->seekg(0, std::ios::end).tellg();
m_stream->clear();
m_stream->seekg(current);
+ m_stream->clear();
+
+ // Return max for a non-seekable stream
+ // https://www.cplusplus.com/reference/istream/istream/tellg/
+ if (end == static_cast<std::streampos>(-1))
+ return LWORD_MAX;
+
return end-current;
}
|