Coverage Report

Created: 2025-07-11 06:25

/src/igraph/fuzzing/edge_connectivity.cpp
Line
Count
Source
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
1.03k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
25
1.03k
    igraph_t graph;
26
1.03k
    igraph_vector_int_t edges;
27
28
1.03k
    igraph_set_warning_handler(igraph_warning_handler_ignore);
29
30
1.03k
    if (Size % 2 == 1 || Size > 65280) {
31
5
        return 0;
32
5
    }
33
34
1.03k
    igraph_vector_int_init(&edges, Size);
35
2.70M
    for (size_t i=0; i < Size; ++i) {
36
2.70M
        VECTOR(edges)[i] = Data[i];
37
2.70M
    }
38
39
1.03k
    if (! igraph_create(&graph, &edges, 0, IGRAPH_DIRECTED)) {
40
1.03k
        igraph_integer_t conn;
41
42
        /* Enable connectivity checks in order to try to force the fuzzer
43
         * to find connected graphs. Disconnected graphs result in low coverage. */
44
1.03k
        igraph_edge_connectivity(&graph, &conn, 1);
45
1.03k
        igraph_to_undirected(&graph, IGRAPH_TO_UNDIRECTED_COLLAPSE, nullptr);
46
1.03k
        igraph_edge_connectivity(&graph, &conn, 1);
47
48
1.03k
        igraph_destroy(&graph);
49
1.03k
    }
50
51
1.03k
    igraph_vector_int_destroy(&edges);
52
53
1.03k
    IGRAPH_ASSERT(IGRAPH_FINALLY_STACK_EMPTY);
54
55
1.03k
    return 0;  // Non-zero return values are reserved for future use.
56
1.03k
}