From 1245ddec5510bea0ab3eaeb0e1a025fbea4c0027 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Sun, 4 Feb 2018 00:21:39 -0600 Subject: [PATCH] Make encode/decode more testable with return codes --- src/apple2.dec.c | 13 +++++++++++++ src/apple2.enc.c | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/src/apple2.dec.c b/src/apple2.dec.c index b7a8e81..bd3e8a8 100644 --- a/src/apple2.dec.c +++ b/src/apple2.dec.c @@ -34,6 +34,10 @@ apple2_dec_dos(vm_segment *dest, vm_segment *src) { int i, doff, tracklen; + if (dest == NULL || src == NULL) { + return OK; + } + for (i = 0, doff = 0; i < ENC_NUM_TRACKS; i++) { tracklen = apple2_dec_track(dest, src, doff, i); @@ -56,6 +60,15 @@ apple2_dec_dos(vm_segment *dest, vm_segment *src) int apple2_dec_nib(vm_segment *dest, vm_segment *src) { + // It's "ok" if you pass in NULL params; the only time you ever + // would is in testing, because we presume you are testing some + // other aspect of the code there. (Good example: when your test is + // not actually testing apple2_dec_nib, but something that calls + // it.) + if (dest == NULL || src == NULL) { + return OK; + } + return vm_segment_copy(dest, src, 0, 0, src->size); } diff --git a/src/apple2.enc.c b/src/apple2.enc.c index 6ea09ae..620ebe8 100644 --- a/src/apple2.enc.c +++ b/src/apple2.enc.c @@ -25,6 +25,10 @@ apple2_enc_dos(vm_segment *src) vm_segment *dest; int i, doff = 0; + if (src == NULL) { + return NULL; + } + // Use the nibbilized size for a 140k image file dest = vm_segment_create(_140K_NIB_); @@ -65,6 +69,11 @@ apple2_enc_nib(vm_segment *src) { vm_segment *dest; + // No src segment, no return data. + if (src == NULL) { + return NULL; + } + dest = vm_segment_create(src->size); vm_segment_copy(dest, src, 0, 0, src->size);