From 3d1ee7a43eb8c7a0f2ecb285d156f57675faa245 Mon Sep 17 00:00:00 2001 From: David Given Date: Fri, 10 Dec 2021 19:56:00 +0000 Subject: [PATCH] Don't spin in an infinite loop if the decoder tries to find a data record and the matcher fails to find anything, leaving the seek point unchanged. --- arch/ibm/decoder.cc | 2 ++ lib/decoders/decoders.cc | 1 + lib/decoders/decoders.h | 3 +++ lib/fluxmap.h | 5 +++++ 4 files changed, 11 insertions(+) diff --git a/arch/ibm/decoder.cc b/arch/ibm/decoder.cc index 331357c7..ec2f2af7 100644 --- a/arch/ibm/decoder.cc +++ b/arch/ibm/decoder.cc @@ -114,6 +114,8 @@ public: auto idbits = readRawBits(16); const Bytes idbytes = decodeFmMfm(idbits); uint8_t id = idbytes.slice(0, 1)[0]; + if (eof()) + return RecordType::UNKNOWN_RECORD; seek(here); switch (id) diff --git a/lib/decoders/decoders.cc b/lib/decoders/decoders.cc index e2119751..0dee46e4 100644 --- a/lib/decoders/decoders.cc +++ b/lib/decoders/decoders.cc @@ -107,6 +107,7 @@ std::unique_ptr AbstractDecoder::decodeToSectors( break; if (fmr.eof()) break; + fmr.skipToEvent(F_BIT_PULSE); } recordStart = fmr.tell(); if (r == DATA_RECORD) diff --git a/lib/decoders/decoders.h b/lib/decoders/decoders.h index 44ff3e54..f6414cad 100644 --- a/lib/decoders/decoders.h +++ b/lib/decoders/decoders.h @@ -57,6 +57,9 @@ public: void seek(const Fluxmap::Position& pos) { return _fmr->seek(pos); } + bool eof() const + { return _fmr->eof(); } + virtual std::set requiredSectors(unsigned cylinder, unsigned head) const; protected: diff --git a/lib/fluxmap.h b/lib/fluxmap.h index 94a6646c..4c7ebf7f 100644 --- a/lib/fluxmap.h +++ b/lib/fluxmap.h @@ -3,6 +3,7 @@ #include "bytes.h" #include "protocol.h" +#include "fmt/format.h" class RawBits; @@ -17,6 +18,10 @@ public: nanoseconds_t ns() const { return ticks * NS_PER_TICK; } + + operator std::string () { + return fmt::format("[b:{}, t:{}, z:{}]", bytes, ticks, zeroes); + } }; public: