Coverage Report

Created: 2026-01-25 07:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/testdir/tests/capi/luaL_addgsub_test.cc
Line
Count
Source
1
/*
2
 * SPDX-License-Identifier: ISC
3
 *
4
 * Copyright 2023-2026, Sergey Bronnikov.
5
 */
6
7
#include <stdint.h>
8
#include <stddef.h>
9
#include <string.h>
10
#include <stdlib.h>
11
12
#include <fuzzer/FuzzedDataProvider.h>
13
14
#if defined(__cplusplus)
15
extern "C" {
16
#endif /* defined(__cplusplus) */
17
18
#include "lua.h"
19
#include "lualib.h"
20
#include "lauxlib.h"
21
22
#if defined(__cplusplus)
23
} /* extern "C" */
24
#endif /* defined(__cplusplus) */
25
26
extern "C" int
27
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
28
995
{
29
995
  FuzzedDataProvider fdp(data, size);
30
31
995
  lua_State *L = luaL_newstate();
32
995
  if (L == NULL)
33
0
    return 0;
34
35
995
  luaL_Buffer buf;
36
995
  auto str = fdp.ConsumeRandomLengthString(size);
37
995
  luaL_buffinit(L, &buf);
38
995
  luaL_addstring(&buf, str.c_str());
39
40
995
  auto str1 = fdp.ConsumeRandomLengthString(size);
41
995
  auto str2 = fdp.ConsumeRandomLengthString(size);
42
995
  auto str3 = fdp.ConsumeRandomLengthString(size);
43
995
  const char *c_str1 = str1.c_str();
44
995
  const char *c_str2 = str2.c_str();
45
995
  const char *c_str3 = str3.c_str();
46
995
  if (strlen(c_str1) == 0 ||
47
709
      strlen(c_str2) == 0 ||
48
641
      strlen(c_str3) == 0) {
49
377
    luaL_pushresult(&buf);
50
377
    lua_settop(L, 0);
51
377
    lua_close(L);
52
377
    return -1;
53
377
  }
54
618
  luaL_addgsub(&buf, c_str1, c_str2, c_str3);
55
618
  luaL_pushresult(&buf);
56
57
618
  lua_settop(L, 0);
58
618
  lua_close(L);
59
60
618
  return 0;
61
995
}