Coverage Report

Created: 2025-06-20 06:26

/src/igraph/fuzzing/vertex_connectivity.cpp
Line
Count
Source
1
/*
2
   IGraph library.
3
   Copyright (C) 2021-2024  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
840
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
25
840
    igraph_t graph;
26
840
    igraph_vector_int_t edges;
27
28
840
    igraph_set_warning_handler(igraph_warning_handler_ignore);
29
30
840
    if (Size % 2 == 0 || Size > 512+1 || Size < 1) {
31
14
        return 0;
32
14
    }
33
34
826
    igraph_vector_int_init(&edges, Size-1);
35
65.5k
    for (size_t i=0; i < Size-1; ++i) {
36
64.6k
        VECTOR(edges)[i] = Data[i+1];
37
64.6k
    }
38
39
826
    if (igraph_create(&graph, &edges, Data[0], IGRAPH_DIRECTED) == IGRAPH_SUCCESS) {
40
826
        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
826
        igraph_vertex_connectivity(&graph, &conn, true);
45
826
        igraph_to_undirected(&graph, IGRAPH_TO_UNDIRECTED_COLLAPSE, nullptr);
46
826
        igraph_vertex_connectivity(&graph, &conn, true);
47
48
826
        igraph_destroy(&graph);
49
826
    }
50
51
826
    igraph_vector_int_destroy(&edges);
52
53
826
    IGRAPH_ASSERT(IGRAPH_FINALLY_STACK_EMPTY);
54
55
826
    return 0;  // Non-zero return values are reserved for future use.
56
826
}