Coverage Report

Created: 2025-07-11 06:33

/src/testdir/tests/capi/luaL_loadbuffer_test.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * SPDX-License-Identifier: ISC
3
 *
4
 * Copyright 2023, Sergey Bronnikov.
5
 */
6
7
#include <stdint.h>
8
#include <stddef.h>
9
#include <string.h>
10
#include <stdlib.h>
11
12
#include "lua.h"
13
#include "lualib.h"
14
#include "lauxlib.h"
15
16
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
17
3.41k
{
18
3.41k
  lua_State *L = luaL_newstate();
19
3.41k
  if (L == NULL)
20
0
    return 0;
21
22
3.41k
  luaL_openlibs(L);
23
24
#ifdef LUAJIT
25
  /* See https://luajit.org/running.html. */
26
  luaL_dostring(L, "jit.opt.start('hotloop=1')");
27
  luaL_dostring(L, "jit.opt.start('hotexit=1')");
28
  luaL_dostring(L, "jit.opt.start('recunroll=1')");
29
  luaL_dostring(L, "jit.opt.start('callunroll=1')");
30
#endif /* LUAJIT */
31
32
3.41k
  int res = luaL_loadbuffer(L, (const char *)data, size, "fuzz");
33
3.41k
  if (res == LUA_OK) {
34
2.61k
    lua_pcall(L, 0, 0, 0);
35
2.61k
  }
36
37
3.41k
  lua_settop(L, 0);
38
3.41k
  lua_close(L);
39
40
3.41k
  return 0;
41
3.41k
}