From 33d16ae0cd82eb59eca867445b59ea22a0ca9df3 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 12 Jul 2017 21:34:08 -0400 Subject: [PATCH] Fixes: individual static analysers reset tapes, for potential successors. The ZX81 file analyser no longer overruns its buffer upon receiving a file that is shorter than 11 bytes. --- StaticAnalyser/Acorn/StaticAnalyser.cpp | 1 + StaticAnalyser/Commodore/StaticAnalyser.cpp | 1 + StaticAnalyser/Oric/StaticAnalyser.cpp | 3 ++- StaticAnalyser/ZX8081/StaticAnalyser.cpp | 1 + Storage/Data/ZX8081.cpp | 2 +- 5 files changed, 6 insertions(+), 2 deletions(-) diff --git a/StaticAnalyser/Acorn/StaticAnalyser.cpp b/StaticAnalyser/Acorn/StaticAnalyser.cpp index 98edd262d..695c232cd 100644 --- a/StaticAnalyser/Acorn/StaticAnalyser.cpp +++ b/StaticAnalyser/Acorn/StaticAnalyser.cpp @@ -75,6 +75,7 @@ void StaticAnalyser::Acorn::AddTargets( if(tapes.size() > 0) { std::shared_ptr tape = tapes.front(); std::list files = GetFiles(tape); + tape->reset(); // continue if there are any files if(files.size()) { diff --git a/StaticAnalyser/Commodore/StaticAnalyser.cpp b/StaticAnalyser/Commodore/StaticAnalyser.cpp index c1d6aa472..79668e950 100644 --- a/StaticAnalyser/Commodore/StaticAnalyser.cpp +++ b/StaticAnalyser/Commodore/StaticAnalyser.cpp @@ -68,6 +68,7 @@ void StaticAnalyser::Commodore::AddTargets( // check tapes for(auto &tape : tapes) { std::list tape_files = GetFiles(tape); + tape->reset(); if(tape_files.size()) { files.splice(files.end(), tape_files); target.tapes = tapes; diff --git a/StaticAnalyser/Oric/StaticAnalyser.cpp b/StaticAnalyser/Oric/StaticAnalyser.cpp index 342ddd728..915004994 100644 --- a/StaticAnalyser/Oric/StaticAnalyser.cpp +++ b/StaticAnalyser/Oric/StaticAnalyser.cpp @@ -84,8 +84,9 @@ void StaticAnalyser::Oric::AddTargets( int basic10_votes = 0; int basic11_votes = 0; - for(auto tape : tapes) { + for(auto &tape : tapes) { std::list tape_files = GetFiles(tape); + tape->reset(); if(tape_files.size()) { for(auto file : tape_files) { if(file.data_type == File::MachineCode) { diff --git a/StaticAnalyser/ZX8081/StaticAnalyser.cpp b/StaticAnalyser/ZX8081/StaticAnalyser.cpp index f7e86d02a..93fd276c0 100644 --- a/StaticAnalyser/ZX8081/StaticAnalyser.cpp +++ b/StaticAnalyser/ZX8081/StaticAnalyser.cpp @@ -35,6 +35,7 @@ void StaticAnalyser::ZX8081::AddTargets( if(!tapes.empty()) { std::vector files = GetFiles(tapes.front()); + tapes.front()->reset(); if(!files.empty()) { StaticAnalyser::Target target; target.machine = Target::ZX8081; diff --git a/Storage/Data/ZX8081.cpp b/Storage/Data/ZX8081.cpp index da5c6e481..836c85dde 100644 --- a/Storage/Data/ZX8081.cpp +++ b/Storage/Data/ZX8081.cpp @@ -51,7 +51,7 @@ static std::shared_ptr ZX81FileFromData(const std::vector &data) // Look for a file name. size_t data_pointer = 0; int c = 11; - while(c--) { + while(c < data.size() && c--) { if(data[data_pointer] & 0x80) break; data_pointer++; }