MCPcopy Create free account
hub / github.com/defold/defold / LoadTSTRING

Function LoadTSTRING

engine/script/src/script_table.cpp:297–314  ·  view source on GitHub ↗

When loading/unpacking messages/save games, we use pascal strings, and the Lua binary string api

Source from the content-addressed store, hash-verified

295
296 // When loading/unpacking messages/save games, we use pascal strings, and the Lua binary string api
297 static uint32_t LoadTSTRING(lua_State* L, const char* buffer, const char* buffer_end, uint32_t count, PushTableLogger& logger)
298 {
299 uint32_t len;
300 memcpy(&len, buffer, sizeof(uint32_t));
301 size_t value_len = (size_t)len;
302 uint32_t total_size = value_len + sizeof(uint32_t);
303 if (buffer_end - buffer < (intptr_t)total_size)
304 {
305 char log_str[PUSH_TABLE_LOGGER_STR_SIZE];
306 PushTableLogPrint(logger, log_str);
307 char str[512];
308 dmSnPrintf(str, sizeof(str), "Reading outside of buffer at element #%d (string) [value_len=%lu]: wanted to read: %d bytes left: %d [BufStart: %p, BufSize: %lu]\n'%s'", count, value_len, total_size, (uint32_t)(buffer_end - buffer), logger.m_BufferStart, logger.m_BufferSize, log_str);
309 luaL_error(L, "%s", str);
310 }
311
312 lua_pushlstring(L, buffer + sizeof(uint32_t), value_len);
313 return total_size;
314 }
315
316 static void StackPush(dmArray<const void*>& table_stack, const void* p)
317 {

Callers 1

DoPushTableFunction · 0.85

Calls 4

PushTableLogPrintFunction · 0.85
dmSnPrintfFunction · 0.85
luaL_errorFunction · 0.85
lua_pushlstringFunction · 0.85

Tested by

no test coverage detected