From bc74da90dc7fee995101e4c6a86b8b8ebde930d0 Mon Sep 17 00:00:00 2001 From: Maschell Date: Thu, 28 Jul 2022 12:54:31 +0200 Subject: [PATCH] Properly check write results --- source/fs/WUXFileWriter.cpp | 2 +- source/fs/WriteOnlyFileWithCache.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/fs/WUXFileWriter.cpp b/source/fs/WUXFileWriter.cpp index 15482c2..e15a121 100644 --- a/source/fs/WUXFileWriter.cpp +++ b/source/fs/WUXFileWriter.cpp @@ -76,7 +76,7 @@ int32_t WUXFileWriter::writeSector(const uint8_t *buffer, uint32_t numberOfSecto indexTable[this->currentSector] = swap_uint32(this->writtenSector); hashMap[hashOut] = writtenSector; if (isOpen()) { - if (!write((uint8_t *) addr, this->sectorSize)) { + if (write((uint8_t *) addr, this->sectorSize) != this->sectorSize) { DEBUG_FUNCTION_LINE_ERR("Write failed"); return -1; } diff --git a/source/fs/WriteOnlyFileWithCache.cpp b/source/fs/WriteOnlyFileWithCache.cpp index 4379c7e..62ecb3f 100644 --- a/source/fs/WriteOnlyFileWithCache.cpp +++ b/source/fs/WriteOnlyFileWithCache.cpp @@ -45,7 +45,7 @@ WriteOnlyFileWithCache::~WriteOnlyFileWithCache() { bool WriteOnlyFileWithCache::flush() { if (this->writeBufferPos > 0) { int32_t res = CFile::write(static_cast(this->writeBuffer), this->writeBufferPos); - if (res < 0) { + if (res != this->writeBufferPos) { DEBUG_FUNCTION_LINE_ERR("Failed to flush cache, write failed: %d (expected %d)", res, this->writeBufferPos); return false; }