/src/h3/src/apps/fuzzers/fuzzerInternalAlgos.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2022 Uber Technologies, Inc. |
3 | | * |
4 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | * you may not use this file except in compliance with the License. |
6 | | * You may obtain a copy of the License at |
7 | | * |
8 | | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | * |
10 | | * Unless required by applicable law or agreed to in writing, software |
11 | | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | * See the License for the specific language governing permissions and |
14 | | * limitations under the License. |
15 | | */ |
16 | | /** @file |
17 | | * @brief Fuzzer program for internal functions in algos.c |
18 | | */ |
19 | | |
20 | | #include "aflHarness.h" |
21 | | #include "algos.h" |
22 | | #include "h3api.h" |
23 | | #include "utility.h" |
24 | | |
25 | | typedef struct { |
26 | | H3Index index; |
27 | | Direction dir; |
28 | | int rotations; |
29 | | H3Index index2; |
30 | | } inputArgs; |
31 | | |
32 | 711 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
33 | 711 | if (size < sizeof(inputArgs)) { |
34 | 8 | return 0; |
35 | 8 | } |
36 | 703 | const inputArgs *args = (const inputArgs *)data; |
37 | | |
38 | 703 | H3Index out; |
39 | 703 | int rotations = args->rotations; |
40 | 703 | h3NeighborRotations(args->index, args->dir, &rotations, &out); |
41 | | |
42 | 703 | directionForNeighbor(args->index, args->index2); |
43 | | |
44 | 703 | VertexGraph graph; |
45 | 703 | H3Index *h3Set = (H3Index *)data; |
46 | 703 | size_t inputSize = size / sizeof(H3Index); |
47 | 703 | H3Error err = h3SetToVertexGraph(h3Set, inputSize, &graph); |
48 | 703 | if (!err) { |
49 | 604 | LinkedGeoPolygon linkedGeoPolygon; |
50 | 604 | _vertexGraphToLinkedGeo(&graph, &linkedGeoPolygon); |
51 | 604 | H3_EXPORT(destroyLinkedMultiPolygon)(&linkedGeoPolygon); |
52 | 604 | destroyVertexGraph(&graph); |
53 | 604 | } |
54 | 703 | return 0; |
55 | 711 | } |
56 | | |
57 | | AFL_HARNESS_MAIN(sizeof(inputArgs)); |