Coverage Report

Created: 2023-09-30 06:14

/src/testdir/tests/lua_stringtonumber_test.c
Line
Count
Source (jump to first uncovered line)
1
#include <stdint.h>
2
#include <stddef.h>
3
#include <stdlib.h>
4
#include <string.h>
5
#include <assert.h>
6
7
#include "lua.h"
8
#include "lualib.h"
9
#include "lauxlib.h"
10
11
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
12
372
{
13
372
  lua_State *L = luaL_newstate();
14
372
  if (L == NULL)
15
0
    return 0;
16
17
372
  char *str = malloc(size + 1);
18
372
  if (str == NULL) {
19
0
    return 0;
20
0
  }
21
372
  memcpy(str, data, size);
22
372
  str[size] = '\0';
23
24
372
  size_t sz = lua_stringtonumber(L, str);
25
372
  if (sz == 0) {
26
113
    assert(lua_gettop(L) == 0);
27
259
  } else {
28
    /* assert(sz == size + 1); */
29
259
    assert(lua_gettop(L) == 1);
30
259
    assert(lua_isnumber(L, -1) == 1);
31
259
  }
32
33
372
  free(str);
34
372
  lua_settop(L, 0);
35
372
  lua_close(L);
36
37
372
  return 0;
38
372
}