diff options
author | osch <oliver at luced de> | 2018-09-04 21:59:23 +0200 |
---|---|---|
committer | osch <oliver at luced de> | 2018-09-04 22:03:35 +0200 |
commit | d534bfc9586c1260d3255f949b7aa6f48511af3a (patch) | |
tree | 1d626db1933134cc1f127d526ad5cdb30a9775b0 | |
parent | f5f119f51a0241f8bbb1f8710fb37119b375539b (diff) | |
download | lua-llthreads2-d534bfc9586c1260d3255f949b7aa6f48511af3a.tar.gz lua-llthreads2-d534bfc9586c1260d3255f949b7aa6f48511af3a.tar.bz2 lua-llthreads2-d534bfc9586c1260d3255f949b7aa6f48511af3a.zip |
avoid NULL as parameter to lua_concat in llthread_log
-rw-r--r-- | src/llthread.c | 5 | ||||
-rw-r--r-- | test/test_error.lua | 40 |
2 files changed, 35 insertions, 10 deletions
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){ | |||
132 | void llthread_log(lua_State *L, const char *hdr, const char *msg){ | 132 | void llthread_log(lua_State *L, const char *hdr, const char *msg){ |
133 | int top = lua_gettop(L); | 133 | int top = lua_gettop(L); |
134 | lua_rawgetp(L, LUA_REGISTRYINDEX, LLTHREAD_LOGGER_HOLDER); | 134 | lua_rawgetp(L, LUA_REGISTRYINDEX, LLTHREAD_LOGGER_HOLDER); |
135 | if (!msg) | ||
136 | msg = "(no error message)"; | ||
135 | if(lua_isnil(L, -1)){ | 137 | if(lua_isnil(L, -1)){ |
136 | lua_pop(L, 1); | 138 | lua_pop(L, 1); |
137 | fputs(hdr, stderr); | 139 | fputs(hdr, stderr); |
138 | if (msg) fputs(msg, stderr); | 140 | fputs(msg, stderr); |
139 | else fputs("(no error message)", stderr); | ||
140 | fputc('\n', stderr); | 141 | fputc('\n', stderr); |
141 | fflush(stderr); | 142 | fflush(stderr); |
142 | return; | 143 | 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 .. [[ | |||
5 | local llthreads = require"llthreads" | 5 | local llthreads = require"llthreads" |
6 | ]] | 6 | ]] |
7 | 7 | ||
8 | local thread = llthreads.new(include .. [[ | 8 | do |
9 | error({}) | 9 | local thread = llthreads.new(include .. [[ |
10 | ]]) | 10 | error({}) |
11 | 11 | ]]) | |
12 | thread:start() | 12 | |
13 | local ok, err = thread:join() | 13 | thread:start() |
14 | print(ok, err) | 14 | local ok, err = thread:join() |
15 | assert(not ok) | 15 | print(ok, err) |
16 | assert(not ok) | ||
17 | end | ||
18 | do | ||
19 | local thread = llthreads.new(include .. [[ | ||
20 | llthreads.set_logger(function(msg) print("XXX", msg) end) | ||
21 | error({}) | ||
22 | ]]) | ||
23 | |||
24 | thread:start() | ||
25 | local ok, err = thread:join() | ||
26 | print(ok, err) | ||
27 | assert(not ok) | ||
28 | end | ||
29 | do | ||
30 | local thread = llthreads.new(include .. [[ | ||
31 | llthreads.set_logger(function(msg) end) | ||
32 | error({}) | ||
33 | ]]) | ||
34 | |||
35 | thread:start() | ||
36 | local ok, err = thread:join() | ||
37 | print(ok, err) | ||
38 | assert(not ok) | ||
39 | end | ||
16 | print("Done!") | 40 | print("Done!") |
17 | 41 | ||