added comment and assert about an (impossible) division by zero

This commit is contained in:
Roberto Ierusalimschy 2014-10-29 13:02:53 -02:00
parent 59fbbf0a65
commit e9885efc7c
1 changed files with 6 additions and 3 deletions

9
lgc.c
View File

@ -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
** 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;
** cycle will start when memory use hits threshold
** Set a reasonable "time" to wait before starting a new GC cycle; cycle
** 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) {
l_mem threshold, debt;
l_mem estimate = g->GCestimate / PAUSEADJ; /* adjust 'estimate' */
lua_assert(estimate > 0);
threshold = (g->gcpause < MAX_LMEM / estimate) /* overflow? */
? estimate * g->gcpause /* no overflow */
: MAX_LMEM; /* overflow; truncate to maximum */