summaryrefslogtreecommitdiff
path: root/zen/serialize.h
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2020-02-15 11:50:31 -0500
committerB Stack <bgstack15@gmail.com>2020-02-15 11:50:31 -0500
commit791b90b9898cc41869538f1dfc303588436682b7 (patch)
tree02cc7f817d95ce3f21207cbaba130e3d537fc1eb /zen/serialize.h
parentMerge branch '10.19' into 'master' (diff)
downloadFreeFileSync-791b90b9898cc41869538f1dfc303588436682b7.tar.gz
FreeFileSync-791b90b9898cc41869538f1dfc303588436682b7.tar.bz2
FreeFileSync-791b90b9898cc41869538f1dfc303588436682b7.zip
add upstream 10.20
It is worth noting that the send email feature is not present in the GPL release.
Diffstat (limited to 'zen/serialize.h')
-rw-r--r--zen/serialize.h18
1 files changed, 9 insertions, 9 deletions
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 <class BinContainer>
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;
bgstack15