| 1415 | |
| 1416 | |
| 1417 | static int str_packsize (lua_State *L) { |
| 1418 | Header h; |
| 1419 | const char *fmt = luaL_checkstring(L, 1); /* format string */ |
| 1420 | size_t totalsize = 0; /* accumulate total size of result */ |
| 1421 | initheader(L, &h); |
| 1422 | while (*fmt != '\0') { |
| 1423 | int size, ntoalign; |
| 1424 | KOption opt = getdetails(&h, totalsize, &fmt, &size, &ntoalign); |
| 1425 | size += ntoalign; /* total space used by option */ |
| 1426 | luaL_argcheck(L, totalsize <= MAXSIZE - size, 1, |
| 1427 | "format result too large"); |
| 1428 | totalsize += size; |
| 1429 | switch (opt) { |
| 1430 | case Kstring: /* strings with length count */ |
| 1431 | case Kzstr: /* zero-terminated string */ |
| 1432 | luaL_argerror(L, 1, "variable-length format"); |
| 1433 | /* call never return, but to avoid warnings: *//* FALLTHROUGH */ |
| 1434 | default: break; |
| 1435 | } |
| 1436 | } |
| 1437 | lua_pushinteger(L, (lua_Integer)totalsize); |
| 1438 | return 1; |
| 1439 | } |
| 1440 | |
| 1441 | |
| 1442 | /* |
nothing calls this directly
no test coverage detected