From d3bde16430aee4f794b3247e5b5c73bc60bfe455 Mon Sep 17 00:00:00 2001 From: mikee47 Date: Fri, 8 Feb 2019 21:22:11 +0000 Subject: [PATCH] Check current position against `size` in `FileStream::write()` and `FileStream::seek()` Fixes problem where `available()` reports negative value --- Sming/SmingCore/Data/Stream/FileStream.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Sming/SmingCore/Data/Stream/FileStream.cpp b/Sming/SmingCore/Data/Stream/FileStream.cpp index 5e2512dc47..053f3188b1 100644 --- a/Sming/SmingCore/Data/Stream/FileStream.cpp +++ b/Sming/SmingCore/Data/Stream/FileStream.cpp @@ -76,16 +76,19 @@ size_t FileStream::write(const uint8_t* buffer, size_t size) return 0; } - int pos = fileSeek(handle, 0, eSO_FileEnd); - if(!check(pos)) { + int writePos = fileSeek(handle, 0, eSO_FileEnd); + if(!check(writePos)) { return 0; } - this->pos = size_t(pos); + pos = size_t(writePos); int written = fileWrite(handle, buffer, size); if(check(written)) { - this->pos += size_t(written); + pos += size_t(written); + if(pos > this->size) { + this->size = pos; + } } return written; @@ -98,7 +101,10 @@ bool FileStream::seek(int len) return false; } - pos = newpos; + pos = size_t(newpos); + if(pos > size) { + size = pos; + } return true; }