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

Function str_rep

third-party/lua-5.2.4/src/lstrlib.c:108–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106#define MAXSIZE ((~(size_t)0) >> 1)
107
108static int str_rep (lua_State *L) {
109 size_t l, lsep;
110 const char *s = luaL_checklstring(L, 1, &l);
111 int n = luaL_checkint(L, 2);
112 const char *sep = luaL_optlstring(L, 3, "", &lsep);
113 if (n <= 0) lua_pushliteral(L, "");
114 else if (l + lsep < l || l + lsep >= MAXSIZE / n) /* may overflow? */
115 return luaL_error(L, "resulting string too large");
116 else {
117 size_t totallen = n * l + (n - 1) * lsep;
118 luaL_Buffer b;
119 char *p = luaL_buffinitsize(L, &b, totallen);
120 while (n-- > 1) { /* first n-1 copies (followed by separator) */
121 memcpy(p, s, l * sizeof(char)); p += l;
122 if (lsep > 0) { /* avoid empty 'memcpy' (may be expensive) */
123 memcpy(p, sep, lsep * sizeof(char)); p += lsep;
124 }
125 }
126 memcpy(p, s, l * sizeof(char)); /* last copy (not followed by separator) */
127 luaL_pushresultsize(&b, totallen);
128 }
129 return 1;
130}
131
132
133static int str_byte (lua_State *L) {

Callers

nothing calls this directly

Calls 5

luaL_checklstringFunction · 0.70
luaL_optlstringFunction · 0.70
luaL_errorFunction · 0.70
luaL_buffinitsizeFunction · 0.70
luaL_pushresultsizeFunction · 0.70

Tested by

no test coverage detected