1c5f01b2fSopenharmony_ci// This file is distributed under the University of Illinois Open Source
2c5f01b2fSopenharmony_ci// License. See LICENSE.TXT for details.
3c5f01b2fSopenharmony_ci
4c5f01b2fSopenharmony_ci// Make sure LLVMFuzzerInitialize is called.
5c5f01b2fSopenharmony_ci#include <assert.h>
6c5f01b2fSopenharmony_ci#include <stddef.h>
7c5f01b2fSopenharmony_ci#include <stdint.h>
8c5f01b2fSopenharmony_ci#include <stdio.h>
9c5f01b2fSopenharmony_ci#include <stdlib.h>
10c5f01b2fSopenharmony_ci#include <string.h>
11c5f01b2fSopenharmony_ci
12c5f01b2fSopenharmony_cistatic char *argv0;
13c5f01b2fSopenharmony_ci
14c5f01b2fSopenharmony_ciextern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) {
15c5f01b2fSopenharmony_ci  assert(*argc > 0);
16c5f01b2fSopenharmony_ci  argv0 = **argv;
17c5f01b2fSopenharmony_ci  fprintf(stderr, "LLVMFuzzerInitialize: %s\n", argv0);
18c5f01b2fSopenharmony_ci  return 0;
19c5f01b2fSopenharmony_ci}
20c5f01b2fSopenharmony_ci
21c5f01b2fSopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
22c5f01b2fSopenharmony_ci  if (Size == strlen(argv0) &&
23c5f01b2fSopenharmony_ci      !strncmp(reinterpret_cast<const char *>(Data), argv0, Size)) {
24c5f01b2fSopenharmony_ci    fprintf(stderr, "BINGO %s\n", argv0);
25c5f01b2fSopenharmony_ci    exit(1);
26c5f01b2fSopenharmony_ci  }
27c5f01b2fSopenharmony_ci  return 0;
28c5f01b2fSopenharmony_ci}
29