1 //===-- yaml-numeric-parser-fuzzer.cpp - Fuzzer for YAML numeric parser ---===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/StringRef.h"
10 #include "llvm/Support/Regex.h"
11 #include "llvm/Support/YAMLTraits.h"
14 inline bool isNumericRegex(llvm::StringRef S
) {
15 static llvm::Regex
Infinity("^[-+]?(\\.inf|\\.Inf|\\.INF)$");
16 static llvm::Regex
Base8("^0o[0-7]+$");
17 static llvm::Regex
Base16("^0x[0-9a-fA-F]+$");
18 static llvm::Regex
Float(
19 "^[-+]?(\\.[0-9]+|[0-9]+(\\.[0-9]*)?)([eE][-+]?[0-9]+)?$");
21 if (S
.equals(".nan") || S
.equals(".NaN") || S
.equals(".NAN"))
24 if (Infinity
.match(S
))
39 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data
, size_t Size
) {
40 std::string
Input(reinterpret_cast<const char *>(Data
), Size
);
41 llvm::erase(Input
, 0);
42 if (!Input
.empty() && llvm::yaml::isNumeric(Input
) != isNumericRegex(Input
))