diff options
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; + } } } |