/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 | 361 | { |
13 | 361 | lua_State *L = luaL_newstate(); |
14 | 361 | if (L == NULL) |
15 | 0 | return 0; |
16 | | |
17 | 361 | size_t str_len = size + 1; |
18 | 361 | char *str = calloc(str_len, sizeof(char)); |
19 | 361 | if (str == NULL) { |
20 | 0 | return 0; |
21 | 0 | } |
22 | 361 | memcpy(str, data, size); |
23 | 361 | str[size] = '\0'; |
24 | | |
25 | 361 | size_t sz = lua_stringtonumber(L, str); |
26 | 361 | if (sz == 0) { |
27 | 109 | assert(lua_gettop(L) == 0); |
28 | 252 | } else { |
29 | | /* assert(sz == size + 1); */ |
30 | 252 | assert(lua_gettop(L) == 1); |
31 | 252 | assert(lua_isnumber(L, -1) == 1); |
32 | 252 | } |
33 | | |
34 | 361 | free(str); |
35 | 361 | lua_settop(L, 0); |
36 | 361 | lua_close(L); |
37 | | |
38 | 361 | return 0; |
39 | 361 | } |