From cbba6a55951ff4aa91aefac46f557bffc98c1cf5 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 23 Dec 2017 19:54:42 -0500 Subject: [PATCH] Ensures final few bytes of a CAS file aren't dropped. --- Storage/Tape/Formats/CAS.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Storage/Tape/Formats/CAS.cpp b/Storage/Tape/Formats/CAS.cpp index 22b572aa0..6ea0b037a 100644 --- a/Storage/Tape/Formats/CAS.cpp +++ b/Storage/Tape/Formats/CAS.cpp @@ -52,12 +52,18 @@ CAS::CAS(const char *file_name) { // Add a new chunk for the new incoming data. active_file->chunks.emplace_back(); - // Keep going until another header arrives. + // Keep going until another header arrives or the file ends. while(std::memcmp(lookahead, header_signature, sizeof(header_signature)) && !file.eof()) { active_file->chunks.back().push_back(lookahead[0]); get_next(file, lookahead, 1); } + // If the file ended, flush the lookahead. + if(file.eof()) { + for(int index = 0; index < 8; index++) + active_file->chunks.back().push_back(lookahead[index]); + } + switch(active_file->type) { case Block::ASCII: // ASCII files have as many chunks as necessary, the final one being back filled