aboutsummaryrefslogtreecommitdiff
path: root/lauxlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lauxlib.c')
-rw-r--r--lauxlib.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/lauxlib.c b/lauxlib.c
index 99a63092..5aeec55f 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -538,10 +538,12 @@ static void newbox (lua_State *L) {
538*/ 538*/
539static size_t newbuffsize (luaL_Buffer *B, size_t sz) { 539static size_t newbuffsize (luaL_Buffer *B, size_t sz) {
540 size_t newsize = (B->size / 2) * 3; /* buffer size * 1.5 */ 540 size_t newsize = (B->size / 2) * 3; /* buffer size * 1.5 */
541 if (l_unlikely(MAX_SIZET - sz - 1 < B->n)) /* overflow in (B->n + sz + 1)? */ 541 if (l_unlikely(sz > MAX_SIZE - B->n - 1))
542 return luaL_error(B->L, "buffer too large"); 542 return luaL_error(B->L, "resulting string too large");
543 if (newsize < B->n + sz + 1) /* not big enough? */ 543 if (newsize < B->n + sz + 1 || newsize > MAX_SIZE) {
544 /* newsize was not big enough or too big */
544 newsize = B->n + sz + 1; 545 newsize = B->n + sz + 1;
546 }
545 return newsize; 547 return newsize;
546} 548}
547 549