From 49592ebaf3d6401ce2094be9f99f10bc1c0cff06 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 12 May 2018 18:42:07 -0400 Subject: [PATCH] Ensures initialisation of `scanner` and that sectors overlapping the end of track are captured. --- Storage/Disk/Encodings/AppleGCR/SegmentParser.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Storage/Disk/Encodings/AppleGCR/SegmentParser.cpp b/Storage/Disk/Encodings/AppleGCR/SegmentParser.cpp index ce21e78f6..cfac4c000 100644 --- a/Storage/Disk/Encodings/AppleGCR/SegmentParser.cpp +++ b/Storage/Disk/Encodings/AppleGCR/SegmentParser.cpp @@ -45,11 +45,15 @@ std::map Storage::Encodings::AppleGCR::sectors_from_segment std::size_t sector_location = 0; std::size_t pointer = scanning_sentinel; std::array header{{0, 0, 0, 0, 0, 0, 0, 0}}; - std::array scanner; + std::array scanner{{0, 0, 0}}; + + // Scan the track 1 and 1/8th times; that's long enough to make sure that any sector which straddles the + // end of the track is caught. Since they're put into a map, it doesn't matter if they're caught twice. + unsigned int extended_length = segment.number_of_bits + (segment.number_of_bits >> 3); + for(unsigned int bit = 0; bit < extended_length; ++bit) { + shift_register = static_cast((shift_register << 1) | segment.bit(bit % segment.number_of_bits)); - for(unsigned int bit = 0; bit < segment.number_of_bits; ++bit) { // Apple GCR parsing: bytes always have the top bit set. - shift_register = static_cast((shift_register << 1) | segment.bit(bit)); if(!(shift_register&0x80)) continue; // Grab the byte. @@ -76,7 +80,7 @@ std::map Storage::Encodings::AppleGCR::sectors_from_segment new_sector.reset(new Sector); new_sector->data.reserve(412); } else { - sector_location = static_cast(bit); + sector_location = static_cast(bit % segment.number_of_bits); } } } else {