Error gracefully when requested to write a too-large scp image

This prevents a crash when more tracks were recorded than fit in an
scp image. When I first encountered a problem doing an 84-track operation,
this led to a segfault later on since memory was written past the end
of _fileheader, and (I think) stomped on a pointer.
This commit is contained in:
Jeff Epler
2022-02-11 09:10:14 -06:00
parent ca2e37e852
commit a6bf6f901f

View File

@@ -85,6 +85,12 @@ public:
trackdataWriter.seekToEnd();
int strack = strackno(cylinder, head);
if (strack >= std::size(_fileheader.track)) {
std::cout << fmt::format("SCP: cannot write track {} head {}, "
"there are not not enough Track Data Headers.\n",
cylinder, head);
return;
}
ScpTrack trackheader = {0};
trackheader.header.track_id[0] = 'T';
trackheader.header.track_id[1] = 'R';