summaryrefslogtreecommitdiff
path: root/test/fuzzer/UseAfterDtor.cpp
blob: dcefca5cc7d58ae7f8fdf2c46b67757b2e8b05d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <cstdint>
#include <cstdio>

struct Simple {
  int x_;
  Simple() {
    x_ = 5;
  }
  ~Simple() {
    x_ += 1;
  }
};

Simple *volatile SimpleSink;

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
  if (Size < 4) return 0;
  if (Data[0] == 'F' && Data[1] == 'U' && Data[2] == 'Z' && Data[3] == 'Z') {
    {
      Simple S;
      SimpleSink = &S;
    }
    if (SimpleSink->x_) fprintf(stderr, "Failed to catch use-after-dtor\n");
  }
  return 0;
}