Coverage Report

Created: 2025-07-18 07:03

/src/testdir/tests/capi/luaL_dostring_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
8.32k
{
18
8.32k
  lua_State *L = luaL_newstate();
19
8.32k
  if (L == NULL)
20
0
    return 0;
21
22
8.32k
  luaL_openlibs(L);
23
24
8.32k
  char *str = malloc(size + 1);
25
8.32k
  if (str == NULL)
26
0
    return 0;
27
8.32k
  memcpy(str, data, size);
28
8.32k
  str[size] = '\0';
29
30
#ifdef LUAJIT
31
  /* See https://luajit.org/running.html. */
32
  luaL_dostring(L, "jit.opt.start('hotloop=1')");
33
  luaL_dostring(L, "jit.opt.start('hotexit=1')");
34
  luaL_dostring(L, "jit.opt.start('recunroll=1')");
35
  luaL_dostring(L, "jit.opt.start('callunroll=1')");
36
#endif /* LUAJIT */
37
8.32k
  luaL_dostring(L, str);
38
39
8.32k
  free(str);
40
8.32k
  lua_settop(L, 0);
41
8.32k
  lua_close(L);
42
43
8.32k
  return 0;
44
8.32k
}