From e54537886cc401dd3af5b2ab23e70e641cbdbad5 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sat, 28 Mar 2020 08:28:09 +0000 Subject: [PATCH] changed to call hawk_rtx_cleario() before restoring SIGPIPE handler in bin/main.c --- hawk/bin/main.c | 5 +++++ hawk/lib/fnc.c | 4 ++-- hawk/lib/run.c | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/hawk/bin/main.c b/hawk/bin/main.c index 20d925e0..9cd20449 100644 --- a/hawk/bin/main.c +++ b/hawk/bin/main.c @@ -1221,6 +1221,11 @@ static HAWK_INLINE int execute_hawk (int argc, hawk_bch_t* argv[]) hawk_rtx_execwithbcstrarr(rtx, (const hawk_bch_t**)arg.icf.ptr, arg.icf.size); #endif + /* clear unflushed io data - this is also done by hawk_rtx_close(). + * but i restore the SIGPIPE handler to the default in unset_intr_run(). + * any output after this restoration may cause the program to terminate for unhandled SIGPIPE */ + hawk_rtx_cleario (rtx); + unset_intr_run (); if (retv) diff --git a/hawk/lib/fnc.c b/hawk/lib/fnc.c index ebd461e3..21e6c84d 100644 --- a/hawk/lib/fnc.c +++ b/hawk/lib/fnc.c @@ -432,7 +432,7 @@ static int flush_io (hawk_rtx_t* rtx, int rio, const hawk_ooch_t* name, int n) if (rtx->rio.handler[rio] != HAWK_NULL) { - n2 = hawk_rtx_flushio (rtx, rio, name); + n2 = hawk_rtx_flushio(rtx, rio, name); if (n2 <= -1) { /* @@ -478,7 +478,7 @@ static int fnc_fflush (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) * BEGIN { flush(); } # flush() returns -1 * BEGIN { print 1; flush(); } # flush() returns 0 */ - n = hawk_rtx_flushio (rtx, HAWK_OUT_CONSOLE, HAWK_T("")); + n = hawk_rtx_flushio(rtx, HAWK_OUT_CONSOLE, HAWK_T("")); } else { diff --git a/hawk/lib/run.c b/hawk/lib/run.c index 409225b8..e372bf79 100644 --- a/hawk/lib/run.c +++ b/hawk/lib/run.c @@ -3356,7 +3356,7 @@ static int run_printf (hawk_rtx_t* rtx, hawk_nde_print_t* nde) HAWK_ASSERT (head != HAWK_NULL); v = eval_expression(rtx, head); - if (v == HAWK_NULL) goto oops_1; + if (HAWK_UNLIKELY(!v)) goto oops_1; hawk_rtx_refupval (rtx, v); vtype = HAWK_RTX_GETVALTYPE(rtx, v); @@ -5547,8 +5547,8 @@ static hawk_val_t* eval_binop_match0 ( hawk_oocs_t out; int n; - out.ptr = hawk_rtx_getvaloocstr (rtx, left, &out.len); - if (out.ptr == HAWK_NULL) return HAWK_NULL; + out.ptr = hawk_rtx_getvaloocstr(rtx, left, &out.len); + if (HAWK_UNLIKELY(!out.ptr)) return HAWK_NULL; n = hawk_rtx_matchvalwithoocs(rtx, right, &out, &out, HAWK_NULL, HAWK_NULL); hawk_rtx_freevaloocstr (rtx, left, out.ptr);