| 95 | |
| 96 | |
| 97 | void *luaM_growaux_ (lua_State *L, void *block, int nelems, int *psize, |
| 98 | int size_elems, int limit, const char *what) { |
| 99 | void *newblock; |
| 100 | int size = *psize; |
| 101 | if (nelems + 1 <= size) /* does one extra element still fit? */ |
| 102 | return block; /* nothing to be done */ |
| 103 | if (size >= limit / 2) { /* cannot double it? */ |
| 104 | if (l_unlikely(size >= limit)) /* cannot grow even a little? */ |
| 105 | luaG_runerror(L, "too many %s (limit is %d)", what, limit); |
| 106 | size = limit; /* still have at least one free place */ |
| 107 | } |
| 108 | else { |
| 109 | size *= 2; |
| 110 | if (size < MINSIZEARRAY) |
| 111 | size = MINSIZEARRAY; /* minimum size */ |
| 112 | } |
| 113 | lua_assert(nelems + 1 <= size && size <= limit); |
| 114 | /* 'limit' ensures that multiplication will not overflow */ |
| 115 | newblock = luaM_saferealloc_(L, block, cast_sizet(*psize) * size_elems, |
| 116 | cast_sizet(size) * size_elems); |
| 117 | *psize = size; /* update only when everything else is OK */ |
| 118 | return newblock; |
| 119 | } |
| 120 | |
| 121 | |
| 122 | /* |
nothing calls this directly
no test coverage detected