/src/testdir/tests/capi/lua_stringtonumber_test.c
Line | Count | Source (jump to first uncovered line) |
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 | 377 | { |
19 | 377 | lua_State *L = luaL_newstate(); |
20 | 377 | if (L == NULL) |
21 | 0 | return 0; |
22 | | |
23 | 377 | char *str = malloc(size + 1); |
24 | 377 | if (str == NULL) { |
25 | 0 | return 0; |
26 | 0 | } |
27 | 377 | memcpy(str, data, size); |
28 | 377 | str[size] = '\0'; |
29 | | |
30 | 377 | size_t sz = lua_stringtonumber(L, str); |
31 | 377 | if (sz == 0) { |
32 | 110 | assert(lua_gettop(L) == 0); |
33 | 267 | } else { |
34 | | /* assert(sz == size + 1); */ |
35 | 267 | assert(lua_gettop(L) == 1); |
36 | 267 | assert(lua_isnumber(L, -1) == 1); |
37 | 267 | } |
38 | | |
39 | 377 | free(str); |
40 | 377 | lua_settop(L, 0); |
41 | 377 | lua_close(L); |
42 | | |
43 | 377 | return 0; |
44 | 377 | } |