Kevin Lubick | 2541edf | 2018-01-11 10:27:14 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "../Fuzz.h" |
| 9 | #include "../FuzzCommon.h" |
| 10 | #include "SkData.h" |
| 11 | #include "SkPath.h" |
| 12 | #include "SkRegion.h" |
| 13 | |
| 14 | |
| 15 | void FuzzRegionSetPath(Fuzz* fuzz) { |
| 16 | SkPath p; |
| 17 | fuzz_path(fuzz, &p, 1000); |
| 18 | SkRegion r1; |
| 19 | bool initR1; |
| 20 | fuzz->next(&initR1); |
| 21 | if (initR1) { |
| 22 | fuzz->next(&r1); |
| 23 | } |
| 24 | SkRegion r2; |
| 25 | fuzz->next(&r2); |
| 26 | |
| 27 | r1.setPath(p, r2); |
| 28 | |
| 29 | // Do some follow on computations to make sure region is well-formed. |
| 30 | r1.computeRegionComplexity(); |
| 31 | r1.isComplex(); |
| 32 | if (r1 == r2) { |
| 33 | r1.contains(0,0); |
| 34 | } else { |
| 35 | r1.contains(1,1); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | #if defined(IS_FUZZING_WITH_LIBFUZZER) |
| 40 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
| 41 | sk_sp<SkData> bytes(SkData::MakeWithoutCopy(data, size)); |
| 42 | Fuzz fuzz(bytes); |
| 43 | FuzzRegionSetPath(&fuzz); |
| 44 | return 0; |
| 45 | } |
| 46 | #endif |