Coverage Report

Created: 2025-11-11 06:55

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