MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / addstr2buff

Function addstr2buff

third-party/lua-5.5.0/src/lobject.c:549–579  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

547
548
549static void addstr2buff (BuffFS *buff, const char *str, size_t slen) {
550 size_t left = buff->buffsize - buff->blen; /* space left in the buffer */
551 if (buff->err) /* do nothing else after an error */
552 return;
553 if (slen > left) { /* new string doesn't fit into current buffer? */
554 if (slen > ((MAX_SIZE/2) - buff->blen)) { /* overflow? */
555 memcpy(buff->b + buff->blen, str, left); /* copy what it can */
556 buff->blen = buff->buffsize;
557 buff->err = 2; /* doesn't add anything else */
558 return;
559 }
560 else {
561 size_t newsize = buff->buffsize + slen; /* limited to MAX_SIZE/2 */
562 char *newb =
563 (buff->b == buff->space) /* still using static space? */
564 ? luaM_reallocvector(buff->L, NULL, 0, newsize, char)
565 : luaM_reallocvector(buff->L, buff->b, buff->buffsize, newsize,
566 char);
567 if (newb == NULL) { /* allocation error? */
568 buff->err = 1; /* signal a memory error */
569 return;
570 }
571 if (buff->b == buff->space) /* new buffer (not reallocated)? */
572 memcpy(newb, buff->b, buff->blen); /* copy previous content */
573 buff->b = newb; /* set new (larger) buffer... */
574 buff->buffsize = newsize; /* ...and its new size */
575 }
576 }
577 memcpy(buff->b + buff->blen, str, slen); /* copy new content */
578 buff->blen += slen;
579}
580
581
582/*

Callers 2

addnum2buffFunction · 0.70
luaO_pushvfstringFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected