Skip to content

Commit

Permalink
overflow check
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwu committed Apr 2, 2019
1 parent 64e0c4d commit 56d24f4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions 3rd/lua/lstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ shrstr_expandpage(unsigned int cap) {
return;
unsigned int osz = s->mask + 1;
unsigned int sz = osz * 2;
// overflow check
if (sz == 0)
return;
while (sz < cap)
sz = sz * 2;
struct shrmap_slot * newpage = shrstr_newpage(sz);
Expand Down Expand Up @@ -655,11 +658,10 @@ luaS_shrinfo(lua_State *L) {
lua_pushinteger(L, total.len); // longest
lua_pushinteger(L, SSM.n); // space
lua_pushinteger(L, slots); // slots
lua_pushnumber(L, v.mean); // average
if (v.count > 1) {
lua_pushnumber(L, v.m2 / v.count); // variance
} else {
lua_pushnumber(L, 0); // variance
}
return 7;
return 6;
}
4 changes: 2 additions & 2 deletions service/debug_console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ function COMMAND.cmem()
end

function COMMAND.shrtbl()
local n, total, longest, space, slots, avg, variance = memory.ssinfo()
return { n = n, total = total, longest = longest, space = space, slots = slots, average = avg, variace = variance }
local n, total, longest, space, slots, variance = memory.ssinfo()
return { n = n, total = total, longest = longest, space = space, slots = slots, average = n / slots, variace = variance }
end

function COMMAND.ping(address)
Expand Down

0 comments on commit 56d24f4

Please sign in to comment.