From e9885efc7c6ef785811c09e1576fb00540ace22c Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 29 Oct 2014 13:02:53 -0200 Subject: added comment and assert about an (impossible) division by zero --- lgc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lgc.c b/lgc.c index 50e5326f..f8af048b 100644 --- a/lgc.c +++ b/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 ** 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 */ -- cgit v1.2.3-55-g6feb