From 791b90b9898cc41869538f1dfc303588436682b7 Mon Sep 17 00:00:00 2001 From: B Stack Date: Sat, 15 Feb 2020 11:50:31 -0500 Subject: add upstream 10.20 It is worth noting that the send email feature is not present in the GPL release. --- zen/serialize.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'zen/serialize.h') diff --git a/zen/serialize.h b/zen/serialize.h index bdeec858..dd884e3b 100644 --- a/zen/serialize.h +++ b/zen/serialize.h @@ -120,7 +120,7 @@ private: template struct MemoryStreamIn { - MemoryStreamIn(const BinContainer& cont) : buffer_(cont) {} //this better be cheap! + explicit MemoryStreamIn(const BinContainer& cont) : buffer_(cont) {} //this better be cheap! size_t read(void* buffer, size_t bytesToRead) //return "bytesToRead" bytes unless end of stream! { @@ -207,11 +207,12 @@ BinContainer bufferedLoad(BufferedInputStream& streamIn) //throw X for (;;) { buffer.resize(buffer.size() + blockSize); - const size_t bytesRead = streamIn.read(&*(buffer.end() - blockSize), blockSize); //throw X; return "bytesToRead" bytes unless end of stream! - buffer.resize(buffer.size() - blockSize + bytesRead); //caveat: unsigned arithmetics - + const size_t bytesRead = streamIn.read(&*(buffer.end() - blockSize), blockSize); //throw X; return "blockSize" bytes unless end of stream! if (bytesRead < blockSize) //end of file + { + buffer.resize(buffer.size() - (blockSize - bytesRead)); //caveat: unsigned arithmetics return buffer; + } } } @@ -270,12 +271,11 @@ C readContainer(BufferedInputStream& stream) //throw UnexpectedEndOfStreamError { try { - cont.resize(strLength); //throw std::bad_alloc - } - catch (std::bad_alloc&) //most likely this is due to data corruption! - { - throw UnexpectedEndOfStreamError(); + cont.resize(strLength); //throw std::length_error } + catch (std::length_error&) { throw UnexpectedEndOfStreamError(); } //most likely this is due to data corruption! + catch ( std::bad_alloc&) { throw UnexpectedEndOfStreamError(); } // + readArray(stream, &*cont.begin(), sizeof(typename C::value_type) * strLength); //throw UnexpectedEndOfStreamError } return cont; -- cgit