Coverage Report

Created: 2026-01-10 06:59

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
362
{
19
362
  lua_State *L = luaL_newstate();
20
362
  if (L == NULL)
21
0
    return 0;
22
23
362
  char *str = malloc(size + 1);
24
362
  if (str == NULL) {
25
0
    return 0;
26
0
  }
27
362
  memcpy(str, data, size);
28
362
  str[size] = '\0';
29
30
362
  size_t sz = lua_stringtonumber(L, str);
31
362
  if (sz == 0) {
32
107
    assert(lua_gettop(L) == 0);
33
255
  } else {
34
    /* assert(sz == size + 1); */
35
255
    assert(lua_gettop(L) == 1);
36
255
    assert(lua_isnumber(L, -1) == 1);
37
255
  }
38
39
362
  free(str);
40
362
  lua_settop(L, 0);
41
362
  lua_close(L);
42
43
362
  return 0;
44
362
}