added comment and assert about an (impossible) division by zero
This commit is contained in:
9
lgc.c
9
lgc.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lgc.c,v 2.196 2014/10/03 12:54:37 roberto Exp roberto $
|
** $Id: lgc.c,v 2.197 2014/10/25 11:50:46 roberto Exp roberto $
|
||||||
** Garbage Collector
|
** Garbage Collector
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -909,12 +909,15 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** set a reasonable "time" to wait before starting a new GC cycle;
|
** Set a reasonable "time" to wait before starting a new GC cycle; cycle
|
||||||
** cycle will start when memory use hits threshold
|
** will start when memory use hits threshold. (Division by 'estimate'
|
||||||
|
** should be OK: it cannot be zero (because Lua cannot even start with
|
||||||
|
** less than PAUSEADJ bytes).
|
||||||
*/
|
*/
|
||||||
static void setpause (global_State *g) {
|
static void setpause (global_State *g) {
|
||||||
l_mem threshold, debt;
|
l_mem threshold, debt;
|
||||||
l_mem estimate = g->GCestimate / PAUSEADJ; /* adjust 'estimate' */
|
l_mem estimate = g->GCestimate / PAUSEADJ; /* adjust 'estimate' */
|
||||||
|
lua_assert(estimate > 0);
|
||||||
threshold = (g->gcpause < MAX_LMEM / estimate) /* overflow? */
|
threshold = (g->gcpause < MAX_LMEM / estimate) /* overflow? */
|
||||||
? estimate * g->gcpause /* no overflow */
|
? estimate * g->gcpause /* no overflow */
|
||||||
: MAX_LMEM; /* overflow; truncate to maximum */
|
: MAX_LMEM; /* overflow; truncate to maximum */
|
||||||
|
|||||||
Reference in New Issue
Block a user