blob: 017e85aabf6ea92f83a2111cc6d2b0ab40cea941 [file] [log] [blame]
Matt Morehousee29452b2017-10-13 17:35:37 +00001//===--- llvm-demangle-fuzzer.cpp - Fuzzer for the Itanium Demangler ------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/Demangle/Demangle.h"
11
12#include <cstdint>
13#include <cstdlib>
14#include <string>
15
16extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
Nico Weber25899272018-12-19 20:18:59 +000017 if (Size == 0)
18 return 0;
19
20 bool UseItanium = Data[0] < 128;
21 std::string NullTerminatedString((const char *)Data + 1, Size - 1);
22
23 if (UseItanium) {
24 free(llvm::itaniumDemangle(NullTerminatedString.c_str(), nullptr, nullptr,
25 nullptr));
26 } else {
27 free(llvm::microsoftDemangle(NullTerminatedString.c_str(), nullptr, nullptr,
28 nullptr));
29 }
Matt Morehousee29452b2017-10-13 17:35:37 +000030
31 return 0;
32}