diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-10-29 13:02:53 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-10-29 13:02:53 -0200 |
commit | e9885efc7c6ef785811c09e1576fb00540ace22c (patch) | |
tree | cdb520bbdbb3523aad2801ab425afbbe376659a6 | |
parent | 59fbbf0a65d4729b65adf07b4d8b4770495cc9b8 (diff) | |
download | lua-e9885efc7c6ef785811c09e1576fb00540ace22c.tar.gz lua-e9885efc7c6ef785811c09e1576fb00540ace22c.tar.bz2 lua-e9885efc7c6ef785811c09e1576fb00540ace22c.zip |
added comment and assert about an (impossible) division by zero
-rw-r--r-- | lgc.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -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 | */ |
915 | static void setpause (global_State *g) { | 917 | static 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 */ |