From 9f9e30a73faac5634ed8aab51ac576031a9d4fb7 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Mon, 17 Nov 2014 20:13:03 +0100 Subject: [PATCH] Check the assertions in cacheReadOneBlock explicitely ...to make the code more robust w.r.t. refactoring. Also add comments about the last block handling. --- encfs/BlockFileIO.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/encfs/BlockFileIO.cpp b/encfs/BlockFileIO.cpp index d567030..b5e9e30 100644 --- a/encfs/BlockFileIO.cpp +++ b/encfs/BlockFileIO.cpp @@ -55,12 +55,17 @@ BlockFileIO::~BlockFileIO() { * returned data as neccessary. */ ssize_t BlockFileIO::cacheReadOneBlock(const IORequest &req) const { - // we can satisfy the request even if _cache.dataLen is too short, because - // we always request a full block during reads.. + + rAssert(req.dataLen <= _blockSize); + rAssert(req.offset % _blockSize == 0); + + /* we can satisfy the request even if _cache.dataLen is too short, because + * we always request a full block during reads. This just means we are + * in the last block of a file, which may be smaller than the blocksize. */ if ((req.offset == _cache.offset) && (_cache.dataLen != 0)) { // satisfy request from cache int len = req.dataLen; - if (_cache.dataLen < len) len = _cache.dataLen; + if (_cache.dataLen < len) len = _cache.dataLen; // Don't read past EOF memcpy(req.data, _cache.data, len); return len; } else {