From d0db131a73933d0a6c65bab59d1e0e4f6a185338 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 6 Jun 2020 13:58:22 +0200 Subject: Code cleanup, use gcc 8 on debian 10 --- archive.h | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'archive.h') diff --git a/archive.h b/archive.h index a98921a..9c9d256 100644 --- a/archive.h +++ b/archive.h @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -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(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(pindex - gindex) < size) + (*mCoro)(); + else + break; + } else { + std::cerr << "Error: read_bytes_vector: Bad stringstream indices: " << pindex << ", " << gindex << std::endl; + break; + } } } -- cgit v1.2.3