| 1 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 2 | // See https://llvm.org/LICENSE.txt for license information. |
| 3 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 4 | |
| 5 | // Tests -trace_malloc |
| 6 | #include <assert.h> |
| 7 | #include <cstddef> |
| 8 | #include <cstdint> |
| 9 | #include <cstdlib> |
| 10 | #include <iostream> |
| 11 | |
| 12 | int *Ptr; |
| 13 | |
| 14 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { |
| 15 | if (!Size) return 0; |
| 16 | if (*Data == 1) { |
| 17 | delete Ptr; |
| 18 | Ptr = nullptr; |
| 19 | } else if (*Data == 2) { |
| 20 | delete Ptr; |
| 21 | Ptr = new int; |
| 22 | } else if (*Data == 3) { |
| 23 | if (!Ptr) |
| 24 | Ptr = new int; |
| 25 | } |
| 26 | return 0; |
| 27 | } |
| 28 | |
| 29 | |