| 77 | |
| 78 | |
| 79 | void *luaM_growaux_ (lua_State *L, void *block, int nelems, int *psize, |
| 80 | int size_elems, int limit, const char *what) { |
| 81 | void *newblock; |
| 82 | int size = *psize; |
| 83 | if (nelems + 1 <= size) /* does one extra element still fit? */ |
| 84 | return block; /* nothing to be done */ |
| 85 | if (size >= limit / 2) { /* cannot double it? */ |
| 86 | if (l_unlikely(size >= limit)) /* cannot grow even a little? */ |
| 87 | luaG_runerror(L, "too many %s (limit is %d)", what, limit); |
| 88 | size = limit; /* still have at least one free place */ |
| 89 | } |
| 90 | else { |
| 91 | size *= 2; |
| 92 | if (size < MINSIZEARRAY) |
| 93 | size = MINSIZEARRAY; /* minimum size */ |
| 94 | } |
| 95 | lua_assert(nelems + 1 <= size && size <= limit); |
| 96 | /* 'limit' ensures that multiplication will not overflow */ |
| 97 | newblock = luaM_saferealloc_(L, block, cast_sizet(*psize) * size_elems, |
| 98 | cast_sizet(size) * size_elems); |
| 99 | *psize = size; /* update only when everything else is OK */ |
| 100 | return newblock; |
| 101 | } |
| 102 | |
| 103 | |
| 104 | /* |
nothing calls this directly
no test coverage detected