diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-06-06 13:58:22 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-06-06 13:58:22 +0200 |
commit | d0db131a73933d0a6c65bab59d1e0e4f6a185338 (patch) | |
tree | 06edad4d845c8ba4102843fc3b306d7b5cc485d6 /archive.h | |
parent | 343922258d57261021daca42eb488c1205ae491c (diff) |
Code cleanup, use gcc 8 on debian 10
Diffstat (limited to 'archive.h')
-rw-r--r-- | archive.h | 29 |
1 files changed, 25 insertions, 4 deletions
@@ -5,6 +5,7 @@ #include <cstdint> #include <ostream> +#include <iostream> #include <istream> #include <sstream> #include <string> @@ -103,8 +104,18 @@ public: { // in coroutine case, wait for input, if necessary if (mCoro && mStringStream) { - while (mStringStream->tellp() - mStringStream->tellg() < sizeof(v)) { - (*mCoro)(); + while (true) { + auto pindex {mStringStream->tellp()}; + auto gindex {mStringStream->tellg()}; + if (pindex != std::stringstream::pos_type(-1) && gindex != std::stringstream::pos_type(-1) && pindex > gindex) { + if (static_cast<size_t>(pindex - gindex) < sizeof(v)) + (*mCoro)(); + else + break; + } else { + std::cerr << "Error: read_fundamental: Bad stringstream indices: " << pindex << ", " << gindex << std::endl; + break; + } } } @@ -153,8 +164,18 @@ public: // in coroutine case, wait for input, if necessary if (mCoro && mStringStream) { - while (mStringStream->tellp() - mStringStream->tellg() < size) { - (*mCoro)(); + while (true) { + auto pindex {mStringStream->tellp()}; + auto gindex {mStringStream->tellg()}; + if (pindex != std::stringstream::pos_type(-1) && gindex != std::stringstream::pos_type(-1) && pindex > gindex) { + if (static_cast<uint32_t>(pindex - gindex) < size) + (*mCoro)(); + else + break; + } else { + std::cerr << "Error: read_bytes_vector: Bad stringstream indices: " << pindex << ", " << gindex << std::endl; + break; + } } } |