From c3e5aa643b2286a327147ebe73370ba8b5a1dcb7 Mon Sep 17 00:00:00 2001 From: "ol.sc" Date: Wed, 22 Feb 2012 23:29:52 +0000 Subject: [PATCH] Learned the hard way that even meant-to-be-simple sample programs should contain some error checking. git-svn-id: svn://svn.cc65.org/cc65/trunk@5546 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- samples/geos/overlay-demo.c | 40 +++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/samples/geos/overlay-demo.c b/samples/geos/overlay-demo.c index 622c06442..cc751ea37 100644 --- a/samples/geos/overlay-demo.c +++ b/samples/geos/overlay-demo.c @@ -65,18 +65,27 @@ void foobar (void) void main(int /*argc*/, char *argv[]) { - OpenRecordFile(argv[0]); + if (OpenRecordFile(argv[0])) { + _poserror("OpenRecordFile"); + return; + } DlgBoxOk(CBOLDON "Overlay Demo - Main" CPLAINTEXT, "Click OK to call Overlay One."); - PointRecord(1); + if (PointRecord(1)) { + _poserror("PointRecord.1"); + return; + } /* The macro definitions OVERLAY_ADDR and OVERLAY_SIZE were generated in * overlay-demores.h by grc65. They contain the overlay area address and * size specific to a certain program. */ - ReadRecord(OVERLAY_ADDR, OVERLAY_SIZE); + if (ReadRecord(OVERLAY_ADDR, OVERLAY_SIZE)) { + _poserror("ReadRecord.1"); + return; + } /* The linker makes sure that the call to foo() ends up at the right mem * addr. However it's up to user to make sure that the - right - overlay @@ -87,23 +96,38 @@ void main(int /*argc*/, char *argv[]) DlgBoxOk(CBOLDON "Overlay Demo - Main" CPLAINTEXT, "Click OK to call Overlay Two."); - PointRecord(2); + if (PointRecord(2)) { + _poserror("PointRecord.2"); + return; + } /* Replacing one overlay with another one can only happen from the main * program. This implies that an overlay can never load another overlay. */ - ReadRecord(OVERLAY_ADDR, OVERLAY_SIZE); + if (ReadRecord(OVERLAY_ADDR, OVERLAY_SIZE)) { + _poserror("ReadRecord.2"); + return; + } bar(); DlgBoxOk(CBOLDON "Overlay Demo - Main" CPLAINTEXT, "Click OK to call Overlay Three."); - PointRecord(3); + if (PointRecord(3)) { + _poserror("PointRecord.3"); + return; + } - ReadRecord(OVERLAY_ADDR, OVERLAY_SIZE); + if (ReadRecord(OVERLAY_ADDR, OVERLAY_SIZE)) { + _poserror("ReadRecord.3"); + return; + } foobar(); - CloseRecordFile(); + if (CloseRecordFile()) { + _poserror("CloseRecordFile"); + return; + } } -- 2.39.5