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