aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-10-29 13:02:53 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-10-29 13:02:53 -0200
commite9885efc7c6ef785811c09e1576fb00540ace22c (patch)
treecdb520bbdbb3523aad2801ab425afbbe376659a6
parent59fbbf0a65d4729b65adf07b4d8b4770495cc9b8 (diff)
downloadlua-e9885efc7c6ef785811c09e1576fb00540ace22c.tar.gz
lua-e9885efc7c6ef785811c09e1576fb00540ace22c.tar.bz2
lua-e9885efc7c6ef785811c09e1576fb00540ace22c.zip
added comment and assert about an (impossible) division by zero
-rw-r--r--lgc.c9
1 files 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 @@
1/* 1/*
2** $Id: lgc.c,v 2.196 2014/10/03 12:54:37 roberto Exp roberto $ 2** $Id: lgc.c,v 2.197 2014/10/25 11:50:46 roberto Exp roberto $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -909,12 +909,15 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {
909 909
910 910
911/* 911/*
912** set a reasonable "time" to wait before starting a new GC cycle; 912** Set a reasonable "time" to wait before starting a new GC cycle; cycle
913** cycle will start when memory use hits threshold 913** will start when memory use hits threshold. (Division by 'estimate'
914** should be OK: it cannot be zero (because Lua cannot even start with
915** less than PAUSEADJ bytes).
914*/ 916*/
915static void setpause (global_State *g) { 917static void setpause (global_State *g) {
916 l_mem threshold, debt; 918 l_mem threshold, debt;
917 l_mem estimate = g->GCestimate / PAUSEADJ; /* adjust 'estimate' */ 919 l_mem estimate = g->GCestimate / PAUSEADJ; /* adjust 'estimate' */
920 lua_assert(estimate > 0);
918 threshold = (g->gcpause < MAX_LMEM / estimate) /* overflow? */ 921 threshold = (g->gcpause < MAX_LMEM / estimate) /* overflow? */
919 ? estimate * g->gcpause /* no overflow */ 922 ? estimate * g->gcpause /* no overflow */
920 : MAX_LMEM; /* overflow; truncate to maximum */ 923 : MAX_LMEM; /* overflow; truncate to maximum */