Skip to content
Myr

Added fuzzer for stb_c_lexer

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Adam Korczynski · committed by Adam Korczynski · parent f54acd4 · Browse files · 1 file+74 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+74 added−0 removed

  • tests:+74 added−0 removed

1 file+74 added−0 removed

added:tests/stb_c_lexer_fuzzer.cpp+74 added
1#define STB_C_LEX_C_DECIMAL_INTS Y 2#define STB_C_LEX_C_HEX_INTS Y3#define STB_C_LEX_C_OCTAL_INTS Y4#define STB_C_LEX_C_DECIMAL_FLOATS Y5#define STB_C_LEX_C99_HEX_FLOATS Y6#define STB_C_LEX_C_IDENTIFIERS Y7#define STB_C_LEX_C_DQ_STRINGS Y8#define STB_C_LEX_C_SQ_STRINGS Y9#define STB_C_LEX_C_CHARS Y10#define STB_C_LEX_C_COMMENTS Y11#define STB_C_LEX_CPP_COMMENTS Y12#define STB_C_LEX_C_COMPARISONS Y13#define STB_C_LEX_C_LOGICAL Y14#define STB_C_LEX_C_SHIFTS Y 15#define STB_C_LEX_C_INCREMENTS Y16#define STB_C_LEX_C_ARROW Y17#define STB_C_LEX_EQUAL_ARROW Y18#define STB_C_LEX_C_BITWISEEQ Y19#define STB_C_LEX_C_ARITHEQ Y2021#define STB_C_LEX_PARSE_SUFFIXES Y22#define STB_C_LEX_DECIMAL_SUFFIXES "uUlL"23#define STB_C_LEX_HEX_SUFFIXES "lL"24#define STB_C_LEX_OCTAL_SUFFIXES "lL"25#define STB_C_LEX_FLOAT_SUFFIXES "uulL"2627#define STB_C_LEX_0_IS_EOF N28#define STB_C_LEX_INTEGERS_AS_DOUBLES N29#define STB_C_LEX_MULTILINE_DSTRINGS Y30#define STB_C_LEX_MULTILINE_SSTRINGS Y31#define STB_C_LEX_USE_STDLIB N32#define STB_C_LEX_DOLLAR_IDENTIFIER Y33#define STB_C_LEX_FLOAT_NO_DECIMAL Y 3435#define STB_C_LEX_DEFINE_ALL_TOKEN_NAMES Y 36#define STB_C_LEX_DISCARD_PREPROCESSOR Y 37#define STB_C_LEXER_DEFINITIONS 3839#define STB_C_LEXER_IMPLEMENTATION40#define STB_C_LEXER_SELF_TEST41#include "../stb_c_lexer.h"42#include <stdint.h>43#include <stdlib.h>44#include <string.h>45#include <stdio.h>464748extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)49{50 if(size<3){51 return 0;52 }53 char *input_stream = (char *)malloc(size);54 if (input_stream == NULL){55 return 0;56 }57 memcpy(input_stream, data, size);5859 stb_lexer lex;60 char *input_end = input_stream+size-1;61 char *store = (char *)malloc(0x10000);62 int len = 0x10000;63 64 stb_c_lexer_init(&lex, input_stream, input_end, store, len);65 while (stb_c_lexer_get_token(&lex)) {66 if (lex.token == CLEX_parse_error) {67 break;68 }69 }70 71 free(input_stream);72 free(store);73 return 0;74}