From e8839df8031caee98e3b302ba26e75e8bff3cb72 Mon Sep 17 00:00:00 2001 From: AJ Bagwell Date: Thu, 16 Dec 2021 15:41:45 +0000 Subject: [PATCH] fix getting address of cluster 0 Due to the changes in 530b663 to suuport larger disk the math to covert a to an address underflows then it cast to a wider int without sign extention leaving a bit set in the middle of the number. This change moves the subtraction to happen after the other additions and widening thus prevting any underflow issues. --- src/core/FatSystem.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/core/FatSystem.cpp b/src/core/FatSystem.cpp index 79cda8c..a137bb4 100644 --- a/src/core/FatSystem.cpp +++ b/src/core/FatSystem.cpp @@ -312,15 +312,14 @@ bool FatSystem::validCluster(unsigned int cluster) unsigned long long FatSystem::clusterAddress(unsigned int cluster, bool isRoot) { - if (type == FAT32 || !isRoot) { - cluster -= 2; - } - unsigned long long addr = (dataStart + bytesPerSector*sectorsPerCluster*cluster); if (type == FAT16 && !isRoot) { addr += rootEntries * FAT_ENTRY_SIZE; } + if (type == FAT32 || !isRoot) { + addr -= bytesPerSector*sectorsPerCluster*2; + } return addr; }