Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ap2_dsk.cpp: add missing error handling code #12980

Merged
merged 1 commit into from
Nov 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/lib/formats/ap2_dsk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ int a2_16sect_format::identify(util::random_read &io, uint32_t form_factor, cons
static const unsigned char cpm22_block1[8] = { 0xa2, 0x55, 0xa9, 0x00, 0x9d, 0x00, 0x0d, 0xca };
static const unsigned char subnod_block1[8] = { 0x63, 0xaa, 0xf0, 0x76, 0x8d, 0x63, 0xaa, 0x8e };

/*auto const [err, actual] =*/ read_at(io, 0, sector_data, 256*2); // FIXME: check for errors and premature EOF
auto const [err, actual] = read_at(io, 0, sector_data, sizeof sector_data);
if (err || actual != sizeof sector_data)
return 0;

bool prodos_order = false;
// check ProDOS boot block
Expand Down Expand Up @@ -309,7 +311,9 @@ bool a2_16sect_format::load(util::random_read &io, uint32_t form_factor, const s
std::vector<uint32_t> track_data;
uint8_t sector_data[256*16];

/*auto const [err, actual] =*/ read_at(io, fpos, sector_data, 256*16); // FIXME: check for errors and premature EOF
auto const [err, actual] = read_at(io, fpos, sector_data, sizeof sector_data);
if (err || actual != sizeof sector_data)
return false;

fpos += 256*16;
for(int i=0; i<49; i++)
Expand Down Expand Up @@ -587,7 +591,9 @@ bool a2_16sect_format::save(util::random_read_write &io, const std::vector<uint3
for(int i=0; i<nsect; i++) {
//if(nsect>0) printf("t%d,", track);
uint8_t const *const data = sectdata + (256)*i;
/*auto const [err, actual] =*/ write_at(io, pos_data, data, 256); // FIXME: check for errors
auto const [err, actual] = write_at(io, pos_data, data, 256);
if (err || actual != 256)
return false;
pos_data += 256;
}
//printf("\n");
Expand Down Expand Up @@ -1165,9 +1171,10 @@ bool a2_edd_format::load(util::random_read &io, uint32_t form_factor, const std:
{
uint8_t nibble[16384], stream[16384];
int npos[16384];
static const size_t img_size = 2'244'608;

auto [err, img, actual] = read_at(io, 0, 2'244'608); // TODO: check for premature EOF
if(err)
auto [err, img, actual] = read_at(io, 0, img_size);
if(err || actual != img_size)
return false;

for(int i=0; i<137; i++) {
Expand Down Expand Up @@ -1404,7 +1411,10 @@ bool a2_nib_format::load(util::random_read &io, uint32_t form_factor, const std:

std::vector<uint8_t> nibbles(nibbles_per_track);
for (unsigned track = 0; track < nr_tracks; ++track) {
/*auto const [err, actual] =*/ read_at(io, track * nibbles_per_track, &nibbles[0], nibbles_per_track); // FIXME: check for errors and premature EOF
auto const [err, actual] = read_at(io, track * nibbles_per_track, &nibbles[0], nibbles_per_track);
if (err || actual != nibbles_per_track)
return false;

auto levels = generate_levels_from_nibbles(nibbles);
if (!levels.empty()) {
generate_track_from_levels(track, 0, levels, 0, image);
Expand Down
Loading