moteus / lua-llthreads2

`llthreads` library rewritten without `LuaNativeObjects` code generator
MIT License
76 stars 22 forks source link

avoid NULL as parameter to fputs() #17

Closed osch closed 6 years ago

osch commented 6 years ago

Passing NULL to fputs() crashes under Linux (I did not try this on other platforms).

This occurs for Lua 5.1 when a non string error is triggerd (e.g. table object): the traceback function for Lua 5.1 in traceback.inc pushes nil onto the stack, whereas for other Lua versions the __tostring metamethod is tried and otherwise the string "(no error message)" is pushed.

I simply put an if (msg) around the fputs() invocation, however other solutions might be better, e.g. trying also to evaluate the __tostring meta method as it is done for newer lua versions.

osch commented 6 years ago

I enhanced the patch for the case, that a custom logger is used via llthreads.set_logger(), because lua_concat() also does not like nil parameters, this results to:

PANIC: unprotected error in call to Lua API (attempt to concatenate a nil value)