/src/igraph/fuzzing/edge_connectivity_fuzzer.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | IGraph library. |
3 | | Copyright (C) 2021-2022 The igraph development team |
4 | | |
5 | | This program is free software; you can redistribute it and/or modify |
6 | | it under the terms of the GNU General Public License as published by |
7 | | the Free Software Foundation; either version 2 of the License, or |
8 | | (at your option) any later version. |
9 | | |
10 | | This program is distributed in the hope that it will be useful, |
11 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | | GNU General Public License for more details. |
14 | | |
15 | | You should have received a copy of the GNU General Public License |
16 | | along with this program; if not, write to the Free Software |
17 | | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 | | 02110-1301 USA |
19 | | */ |
20 | | |
21 | | #include <igraph.h> |
22 | | #include <cstdlib> |
23 | | |
24 | 24.4k | inline void check_err(int err) { |
25 | 24.4k | if (err) |
26 | 0 | abort(); |
27 | 24.4k | } |
28 | | |
29 | 1.16k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { |
30 | 1.16k | igraph_t graph; |
31 | 1.16k | igraph_vector_int_t edges; |
32 | | |
33 | 1.16k | igraph_set_error_handler(igraph_error_handler_ignore); |
34 | 1.16k | igraph_set_warning_handler(igraph_warning_handler_ignore); |
35 | | |
36 | 1.16k | if (Size % 2 == 1 || Size > 65280) { |
37 | 5 | return 0; |
38 | 5 | } |
39 | | |
40 | 1.15k | check_err(igraph_vector_int_init(&edges, Size)); |
41 | 2.99M | for (size_t i=0; i < Size; ++i) { |
42 | 2.99M | VECTOR(edges)[i] = Data[i]; |
43 | 2.99M | } |
44 | | |
45 | 1.15k | if (! igraph_create(&graph, &edges, 0, IGRAPH_DIRECTED)) { |
46 | 1.15k | igraph_integer_t conn; |
47 | | |
48 | | /* Enable connectivity checks in order to try to force the fuzzer |
49 | | * to find connected graphs. Disconnected graphs result in low coverage. */ |
50 | 1.15k | check_err(igraph_edge_connectivity(&graph, &conn, 1)); |
51 | 1.15k | check_err(igraph_to_undirected(&graph, IGRAPH_TO_UNDIRECTED_COLLAPSE, nullptr)); |
52 | 1.15k | check_err(igraph_edge_connectivity(&graph, &conn, 1)); |
53 | | |
54 | 1.15k | igraph_destroy(&graph); |
55 | 1.15k | } |
56 | | |
57 | 1.15k | igraph_vector_int_destroy(&edges); |
58 | | |
59 | 1.15k | IGRAPH_ASSERT(IGRAPH_FINALLY_STACK_EMPTY); |
60 | | |
61 | 1.15k | return 0; // Non-zero return values are reserved for future use. |
62 | 1.15k | } |