From f5f119f51a0241f8bbb1f8710fb37119b375539b Mon Sep 17 00:00:00 2001 From: osch Date: Tue, 4 Sep 2018 21:33:12 +0200 Subject: avoid NULL as parameter to fputs() --- src/llthread.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/llthread.c b/src/llthread.c index 66efe7c..57f8dc3 100644 --- a/src/llthread.c +++ b/src/llthread.c @@ -135,7 +135,8 @@ void llthread_log(lua_State *L, const char *hdr, const char *msg){ if(lua_isnil(L, -1)){ lua_pop(L, 1); fputs(hdr, stderr); - fputs(msg, stderr); + if (msg) fputs(msg, stderr); + else fputs("(no error message)", stderr); fputc('\n', stderr); fflush(stderr); return; -- cgit v1.2.3-55-g6feb From d534bfc9586c1260d3255f949b7aa6f48511af3a Mon Sep 17 00:00:00 2001 From: osch Date: Tue, 4 Sep 2018 21:59:23 +0200 Subject: avoid NULL as parameter to lua_concat in llthread_log --- src/llthread.c | 5 +++-- test/test_error.lua | 40 ++++++++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/llthread.c b/src/llthread.c index 57f8dc3..a3b3216 100644 --- a/src/llthread.c +++ b/src/llthread.c @@ -132,11 +132,12 @@ static int fail(lua_State *L, const char *msg){ void llthread_log(lua_State *L, const char *hdr, const char *msg){ int top = lua_gettop(L); lua_rawgetp(L, LUA_REGISTRYINDEX, LLTHREAD_LOGGER_HOLDER); + if (!msg) + msg = "(no error message)"; if(lua_isnil(L, -1)){ lua_pop(L, 1); fputs(hdr, stderr); - if (msg) fputs(msg, stderr); - else fputs("(no error message)", stderr); + fputs(msg, stderr); fputc('\n', stderr); fflush(stderr); return; diff --git a/test/test_error.lua b/test/test_error.lua index 1407ea8..341105e 100644 --- a/test/test_error.lua +++ b/test/test_error.lua @@ -5,13 +5,37 @@ local include = utils.thread_init .. [[ local llthreads = require"llthreads" ]] -local thread = llthreads.new(include .. [[ - error({}) -]]) - -thread:start() -local ok, err = thread:join() -print(ok, err) -assert(not ok) +do + local thread = llthreads.new(include .. [[ + error({}) + ]]) + + thread:start() + local ok, err = thread:join() + print(ok, err) + assert(not ok) +end +do + local thread = llthreads.new(include .. [[ + llthreads.set_logger(function(msg) print("XXX", msg) end) + error({}) + ]]) + + thread:start() + local ok, err = thread:join() + print(ok, err) + assert(not ok) +end +do + local thread = llthreads.new(include .. [[ + llthreads.set_logger(function(msg) end) + error({}) + ]]) + + thread:start() + local ok, err = thread:join() + print(ok, err) + assert(not ok) +end print("Done!") -- cgit v1.2.3-55-g6feb