From 58216600eba27d472de33dbb89e2f3e629bf8a59 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 3 Nov 2020 16:34:36 -0300 Subject: 'luaL_newstate' should not allocate extra memory The allocation of a userdata for the state of the warn system can cause a panic if it fails; 'luaL_ref' also can fail. This commit re-implements the warn system so that it does not need an explicit state. Instead, the system uses different functions to represent the different states. --- lobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lobject.c') diff --git a/lobject.c b/lobject.c index f8ea917a..0e504be0 100644 --- a/lobject.c +++ b/lobject.c @@ -258,7 +258,7 @@ static const char *l_str2d (const char *s, lua_Number *result) { if (endptr == NULL) { /* failed? may be a different locale */ char buff[L_MAXLENNUM + 1]; const char *pdot = strchr(s, '.'); - if (strlen(s) > L_MAXLENNUM || pdot == NULL) + if (pdot == NULL || strlen(s) > L_MAXLENNUM) return NULL; /* string too long or no dot; fail */ strcpy(buff, s); /* copy string to buffer */ buff[pdot - s] = lua_getlocaledecpoint(); /* correct decimal point */ -- cgit v1.2.3-55-g6feb