From e637abc411e22548e6b234d4a6a20344b1d6d33b Mon Sep 17 00:00:00 2001 From: Guenter Bartsch Date: Thu, 30 Dec 2021 12:03:45 +0100 Subject: [PATCH] use EXIT\_FAILURE for fatal error conditions (fixes issue #13 by polluks) --- CHANGELOG.md | 1 + src/compiler/aqb.c | 2 +- src/compiler/compiler.c | 36 ++++++++++++++++----------------- src/compiler/dis68k.c | 2 +- src/compiler/env.c | 2 +- src/compiler/ide.c | 2 +- src/compiler/link.c | 6 +++--- src/compiler/options.c | 2 +- src/compiler/ui_linux.c | 2 +- src/compiler/util.c | 2 +- src/tools/reactiontest/ratest.c | 6 +++--- 11 files changed, 32 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad63ed53..fb9a0ac3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Improvements: Bug Fixes: * examples: tetris code cleanup, use custom fonts + * use EXIT\_FAILURE for fatal error conditions (fixes issue #13 by polluks) ## 0.8.1 diff --git a/src/compiler/aqb.c b/src/compiler/aqb.c index b3bbe3b7..c0241582 100644 --- a/src/compiler/aqb.c +++ b/src/compiler/aqb.c @@ -102,7 +102,7 @@ static void check_amigaos_env(void) if ( ((struct Library *)DOSBase)->lib_Version < 37) { U_request (NULL, NULL, "OK", "DOS library V%d is too old, need at least V37", ((struct Library *)DOSBase)->lib_Version); - exit(1); + exit(EXIT_FAILURE); } struct Process *aqbProc; diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c index 83519f73..c430f860 100644 --- a/src/compiler/compiler.c +++ b/src/compiler/compiler.c @@ -101,7 +101,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn, if (!sourcef) { LOG_printf (LOG_ERROR, "failed to read %s: %s\n\n", sourcefn, strerror(errno)); - CO_exit(2); + CO_exit(EXIT_FAILURE); } frags = FE_sourceProgram(sourcef, sourcefn, /*is_main=*/!symfn, module_name); @@ -110,7 +110,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn, if (EM_anyErrors) { LOG_printf (LOG_ERROR, "\n\nfrontend processing failed - exiting.\n"); - CO_exit(3); + CO_exit(EXIT_FAILURE); } LOG_printf (OPT_get(OPTION_VERBOSE) ? LOG_INFO : LOG_DEBUG, "\n\nsemantics worked.\n"); @@ -129,7 +129,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn, else { LOG_printf (LOG_ERROR, "\n** ERROR: failed to write symbol file %s .\n", symfn); - CO_exit(4); + CO_exit(EXIT_FAILURE); } } @@ -164,7 +164,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn, if (!RA_regAlloc(frame, body) || EM_anyErrors) { LOG_printf (LOG_ERROR, "\n\nregister allocation failed - exiting.\n"); - CO_exit(5); + CO_exit(EXIT_FAILURE); } CG_procEntryExitAS(frag); @@ -185,7 +185,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn, if (!out) { LOG_printf (LOG_ERROR, "\n\nfailed to open asm file %s for writing.\n", asm_gas_fn); - CO_exit(6); + CO_exit(EXIT_FAILURE); } CG_writeASMFile (out, frags, AS_dialect_gas); fclose(out); @@ -197,7 +197,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn, if (!out) { LOG_printf (LOG_ERROR, "\n\nfailed to open asm file %s for writing.\n", asm_asmpro_fn); - CO_exit(7); + CO_exit(EXIT_FAILURE); } CG_writeASMFile (out, frags, AS_dialect_ASMPro); fclose(out); @@ -209,7 +209,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn, if (!out) { LOG_printf (LOG_ERROR, "\n\nfailed to open asm file %s for writing.\n", asm_vasm_fn); - CO_exit(8); + CO_exit(EXIT_FAILURE); } CG_writeASMFile (out, frags, AS_dialect_vasm); fclose(out); @@ -245,21 +245,21 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn, U_memstat(); if (!AS_assembleCode (obj, body, expt, frame)) - CO_exit(9); + CO_exit(EXIT_FAILURE); break; } case CG_stringFrag: AS_assembleDataAlign2 (obj); if (!AS_assembleString (obj, frag->u.stringg.label, frag->u.stringg.str, frag->u.stringg.msize)) - CO_exit(10); + CO_exit(EXIT_FAILURE); break; case CG_dataFrag: if (!frag->u.data.size) break; AS_assembleDataAlign2 (obj); if (!AS_assembleDataLabel (obj, frag->u.data.label, frag->u.data.expt, frag->u.data.ty)) - CO_exit(11); + CO_exit(EXIT_FAILURE); if (frag->u.data.init) { for (CG_dataFragNode n=frag->u.data.init; n; n=n->next) @@ -268,7 +268,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn, { case CG_labelNode: if (!AS_assembleDataLabel (obj, n->u.label, /*expt=*/FALSE, /*ty=*/NULL)) - CO_exit(12); + CO_exit(EXIT_FAILURE); break; case CG_constNode: { @@ -331,14 +331,14 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn, if (EM_anyErrors) { LOG_printf (LOG_ERROR, "\n\nassembler failed - exiting.\n"); - CO_exit(13); + CO_exit(EXIT_FAILURE); } if (objfn) LI_segmentWriteObjectFile (obj, objfn); if (!binfn) - CO_exit(0); + CO_exit(EXIT_FAILURE); /* * machine code generation (link phase) @@ -352,12 +352,12 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn, if (!fObj) { LOG_printf (LOG_ERROR, "*** ERROR: failed to open startup.o\n\n"); - CO_exit(14); + CO_exit(EXIT_FAILURE); } if (!LI_segmentListReadObjectFile (UP_link, sl, "startup.o", fObj)) { fclose(fObj); - CO_exit(15); + CO_exit(EXIT_FAILURE); } fclose(fObj); @@ -375,12 +375,12 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn, if (!fObj) { LOG_printf (LOG_ERROR, "*** ERROR: failed to open %s\n\n", mod_fn); - CO_exit(16); + CO_exit(EXIT_FAILURE); } if (!LI_segmentListReadObjectFile (UP_link, sl, S_name(n->m->name), fObj)) { fclose(fObj); - CO_exit(17); + CO_exit(EXIT_FAILURE); } fclose(fObj); } @@ -388,7 +388,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn, if (!LI_link (UP_link, sl)) { LOG_printf (LOG_ERROR, "*** ERROR: failed to link.\n\n"); - CO_exit(18); + CO_exit(EXIT_FAILURE); } LI_segmentListWriteLoadFile (sl, binfn); diff --git a/src/compiler/dis68k.c b/src/compiler/dis68k.c index 9975f27d..fb341840 100644 --- a/src/compiler/dis68k.c +++ b/src/compiler/dis68k.c @@ -1033,7 +1033,7 @@ void DEBUG_disasm(IDE_instance ed, unsigned long int start, unsigned long int en } break; default : printf("opnum out of range in switch (=%i)\n", opnum); - exit(1); + exit(EXIT_FAILURE); } } if (decoded) opnum = 88; diff --git a/src/compiler/env.c b/src/compiler/env.c index ff1de383..6c675f5e 100644 --- a/src/compiler/env.c +++ b/src/compiler/env.c @@ -303,7 +303,7 @@ static void env_fail (string msg) modf = NULL; } - exit(126); + exit(EXIT_FAILURE); } static void fwrite_double(FILE *f, double d) diff --git a/src/compiler/ide.c b/src/compiler/ide.c index 20f91784..9911ea13 100644 --- a/src/compiler/ide.c +++ b/src/compiler/ide.c @@ -1476,7 +1476,7 @@ static bool _ide_save (IDE_instance ed, bool save_as) if (!sourcef) { fprintf(stderr, "failed to write %s: %s\n\n", ed->sourcefn, strerror(errno)); - exit(2); + exit(EXIT_FAILURE); } static char *indent_str = " "; diff --git a/src/compiler/link.c b/src/compiler/link.c index b363849d..93279a88 100644 --- a/src/compiler/link.c +++ b/src/compiler/link.c @@ -62,7 +62,7 @@ static void link_fail (string msg) g_fObjFile = NULL; } - CO_exit(127); + CO_exit(EXIT_FAILURE); } #if LOG_LEVEL == LOG_DEBUG @@ -1265,7 +1265,7 @@ void LI_segmentWriteObjectFile (AS_object obj, string objfn) if (!g_fObjFile) { LOG_printf (LOG_ERROR, "*** ERROR: failed to open %s for writing.\n\n", objfn); - exit(128); + CO_exit(EXIT_FAILURE); } write_hunk_unit (objfn, g_fObjFile); @@ -1299,7 +1299,7 @@ void LI_segmentListWriteLoadFile (LI_segmentList sl, string loadfn) if (!g_fLoadFile) { LOG_printf (LOG_ERROR, "*** ERROR: failed to open %s for writing.\n\n", loadfn); - exit(128); + CO_exit(EXIT_FAILURE); } write_hunk_header (sl, g_fLoadFile); diff --git a/src/compiler/options.c b/src/compiler/options.c index 256801d7..6bb743bc 100644 --- a/src/compiler/options.c +++ b/src/compiler/options.c @@ -105,7 +105,7 @@ void OPT_init(void) if (snprintf (g_pref_fn, PATH_MAX, "%s/prefs.ini", aqb_home)<0) { fprintf (stderr, "prefs.ini path too long\n"); - exit(42); + exit(EXIT_FAILURE); } #endif diff --git a/src/compiler/ui_linux.c b/src/compiler/ui_linux.c index dfe7256e..8df65112 100644 --- a/src/compiler/ui_linux.c +++ b/src/compiler/ui_linux.c @@ -286,7 +286,7 @@ static uint16_t UI_getch (void) char c, seq[5]; while ((nread = read(STDIN_FILENO,&c,1)) == 0); if (nread == -1) - exit(1); + exit(EXIT_FAILURE); while(1) { diff --git a/src/compiler/util.c b/src/compiler/util.c index 9913f402..fb31784f 100644 --- a/src/compiler/util.c +++ b/src/compiler/util.c @@ -96,7 +96,7 @@ static void *checked_malloc (size_t len) if (!p) { LOG_printf(LOG_ERROR, "\nran out of memory!\n"); - exit(1); + exit(EXIT_FAILURE); } // fprintf(stderr, "checked_malloc len=%zu -> p=%p\n", len, p); return p; diff --git a/src/tools/reactiontest/ratest.c b/src/tools/reactiontest/ratest.c index ffaf3837..4471e68e 100644 --- a/src/tools/reactiontest/ratest.c +++ b/src/tools/reactiontest/ratest.c @@ -105,15 +105,15 @@ int main(void) cleanexit("failed to open intuition.library\n"); DPRINTF ("intuition.library opened\n"); - if (! (WindowBase = OpenLibrary((STRPTR)"window.class", 47)) ) + if (! (WindowBase = OpenLibrary((STRPTR)"window.class", 37)) ) cleanexit("failed to open window.class\n"); DPRINTF ("window.class opened\n"); - if (! (LayoutBase = OpenLibrary((STRPTR)"gadgets/layout.gadget", 47)) ) + if (! (LayoutBase = OpenLibrary((STRPTR)"gadgets/layout.gadget", 37)) ) cleanexit("failed to open gadgets/layout.gadget\n"); DPRINTF ("gadgets/layout.gadget opened\n"); - if (! (ButtonBase = OpenLibrary((STRPTR)"gadgets/button.gadget", 47)) ) + if (! (ButtonBase = OpenLibrary((STRPTR)"gadgets/button.gadget", 0)) ) cleanexit("failed to open gadgets/button.gadget\n"); DPRINTF ("gadgets/button.gadget opened\n");