Coverage Report

Created: 2024-04-23 06:32

/src/testdir/tests/capi/luaL_bufflen_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
#include <assert.h>
12
13
#include "lua.h"
14
#include "lualib.h"
15
#include "lauxlib.h"
16
17
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
18
255
{
19
255
  lua_State *L = luaL_newstate();
20
255
  if (L == NULL)
21
0
    return 0;
22
23
255
  if (size > LUAI_MAXSTACK)
24
1
    return -1;
25
26
254
  luaL_Buffer buf;
27
254
  char *s = luaL_buffinitsize(L, &buf, size);
28
254
  memcpy(s, data, size);
29
30
254
  luaL_pushresultsize(&buf, size);
31
32
254
  assert(luaL_bufflen(&buf) == size);
33
34
254
  lua_settop(L, 0);
35
254
  lua_close(L);
36
37
254
  return 0;
38
254
}