Coverage Report

Created: 2025-10-13 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/testdir/tests/capi/lua_stringtonumber_test.c
Line
Count
Source
1
/*
2
 * SPDX-License-Identifier: ISC
3
 *
4
 * Copyright 2023, Sergey Bronnikov.
5
 */
6
7
#include <stdint.h>
8
#include <stddef.h>
9
#include <stdlib.h>
10
#include <string.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
359
{
19
359
  lua_State *L = luaL_newstate();
20
359
  if (L == NULL)
21
0
    return 0;
22
23
359
  char *str = malloc(size + 1);
24
359
  if (str == NULL) {
25
0
    return 0;
26
0
  }
27
359
  memcpy(str, data, size);
28
359
  str[size] = '\0';
29
30
359
  size_t sz = lua_stringtonumber(L, str);
31
359
  if (sz == 0) {
32
100
    assert(lua_gettop(L) == 0);
33
259
  } else {
34
    /* assert(sz == size + 1); */
35
259
    assert(lua_gettop(L) == 1);
36
259
    assert(lua_isnumber(L, -1) == 1);
37
259
  }
38
39
359
  free(str);
40
359
  lua_settop(L, 0);
41
359
  lua_close(L);
42
43
359
  return 0;
44
359
}