shithub: lu9

Download patch

ref: 7ac058376998864f82026ce1bb58944be142fb9a
parent: 105936be41440f67cda5d1767991b5c3c5ba6f05
author: kvik <[email protected]>
date: Sun Feb 21 18:05:20 EST 2021

lua: relax fp signaling configuration

This gives user code a chance to suffer^Whandle out-of-range and invalid
results of floating point operations, rather than having the OS kill the
entire process.

Killing the process may be useful for a raw C program, since its state
can be easily inspected to find the place where the (likely) bug
occured.  This isn't the case with Lua programs, for which the process
state is mostly useless in determining the Lua source line that caused
the VM to execute an invalid fp operation.

--- a/lua.c
+++ b/lua.c
@@ -12,6 +12,8 @@
 {
 	lua_State *L;
 	
+	setfcr(getfcr() & ~(FPZDIV | FPOVFL | FPINVAL));
+	
 	if((L = luaL_newstate()) == NULL)
 		sysfatal("out of memory");
 	luaL_openlibs(L);