** Returns a pointer to a free area with at least 'sz' bytes in buffer ** 'B'. 'boxidx' is the relative position in the stack where is the ** buffer's box or its placeholder. */
| 544 | ** buffer's box or its placeholder. |
| 545 | */ |
| 546 | static char *prepbuffsize (luaL_Buffer *B, size_t sz, int boxidx) { |
| 547 | checkbufferlevel(B, boxidx); |
| 548 | if (B->size - B->n >= sz) /* enough space? */ |
| 549 | return B->b + B->n; |
| 550 | else { |
| 551 | lua_State *L = B->L; |
| 552 | char *newbuff; |
| 553 | size_t newsize = newbuffsize(B, sz); |
| 554 | /* create larger buffer */ |
| 555 | if (buffonstack(B)) /* buffer already has a box? */ |
| 556 | newbuff = (char *)resizebox(L, boxidx, newsize); /* resize it */ |
| 557 | else { /* no box yet */ |
| 558 | lua_remove(L, boxidx); /* remove placeholder */ |
| 559 | newbox(L); /* create a new box */ |
| 560 | lua_insert(L, boxidx); /* move box to its intended position */ |
| 561 | lua_toclose(L, boxidx); |
| 562 | newbuff = (char *)resizebox(L, boxidx, newsize); |
| 563 | memcpy(newbuff, B->b, B->n * sizeof(char)); /* copy original content */ |
| 564 | } |
| 565 | B->b = newbuff; |
| 566 | B->size = newsize; |
| 567 | return newbuff + B->n; |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | /* |
| 572 | ** returns a pointer to a free area with at least 'sz' bytes |
no test coverage detected