Coverage Report

Created: 2025-12-05 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/igraph/fuzzing/centrality.cpp
Line
Count
Source
1
/*
2
   igraph library.
3
   Copyright (C) 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
1.34k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
25
1.34k
    igraph_t graph;
26
1.34k
    igraph_vector_int_t edges;
27
28
1.34k
    igraph_set_warning_handler(igraph_warning_handler_ignore);
29
30
1.34k
    if (Size % 2 == 0 || Size > 512+1 || Size < 1) {
31
14
        return 0;
32
14
    }
33
34
1.32k
    igraph_vector_int_init(&edges, Size-1);
35
84.8k
    for (size_t i=0; i < Size-1; ++i) {
36
83.5k
        VECTOR(edges)[i] = Data[i+1];
37
83.5k
    }
38
39
1.32k
    igraph_rng_seed(igraph_rng_default(), 42);
40
41
1.32k
    if (igraph_create(&graph, &edges, Data[0], IGRAPH_DIRECTED) == IGRAPH_SUCCESS) {
42
1.32k
        igraph_vector_t v;
43
1.32k
        igraph_vector_int_t iv;
44
1.32k
        igraph_bool_t b;
45
1.32k
        igraph_real_t r;
46
47
        /* Limit graph size for the sake of performance. */
48
1.32k
        if (igraph_vcount(&graph) <= 64) {
49
1.29k
            igraph_vector_init(&v, 0);
50
1.29k
            igraph_vector_int_init(&iv, 0);
51
52
1.29k
            igraph_betweenness_cutoff(&graph, NULL, &v, igraph_vss_all(), IGRAPH_UNDIRECTED, false, 4);
53
1.29k
            igraph_betweenness_cutoff(&graph, NULL, &v, igraph_vss_all(), IGRAPH_DIRECTED, false, 5);
54
1.29k
            igraph_edge_betweenness_cutoff(&graph, NULL, &v, igraph_ess_all(IGRAPH_EDGEORDER_ID), IGRAPH_DIRECTED,
55
1.29k
                                           false, 4);
56
1.29k
            igraph_edge_betweenness_cutoff(&graph, NULL, &v, igraph_ess_all(IGRAPH_EDGEORDER_ID), IGRAPH_UNDIRECTED,
57
1.29k
                                           false, 3);
58
1.29k
            if (igraph_vcount(&graph) >= 10) {
59
1.18k
                igraph_betweenness_subset(&graph, NULL, &v,
60
1.18k
                                          igraph_vss_range(0,5), igraph_vss_range(5,10),
61
1.18k
                                          igraph_vss_all(), IGRAPH_DIRECTED, false);
62
1.18k
                igraph_edge_betweenness_subset(&graph, NULL, &v,
63
1.18k
                                               igraph_vss_range(0,10), igraph_vss_range(0,10),
64
1.18k
                                               igraph_ess_all(IGRAPH_EDGEORDER_ID), IGRAPH_DIRECTED, false);
65
1.18k
            }
66
1.29k
            igraph_closeness_cutoff(&graph, &v, &iv, &b, igraph_vss_all(), IGRAPH_ALL, NULL, true, 3);
67
1.29k
            igraph_closeness_cutoff(&graph, &v, &iv, &b, igraph_vss_all(), IGRAPH_OUT, NULL, true, 4);
68
1.29k
            igraph_harmonic_centrality_cutoff(&graph, &v, igraph_vss_all(), IGRAPH_ALL, NULL, true, 3);
69
1.29k
            igraph_harmonic_centrality_cutoff(&graph, &v, igraph_vss_all(), IGRAPH_IN, NULL, true, 4);
70
1.29k
            igraph_global_efficiency(&graph, NULL, &r, IGRAPH_DIRECTED);
71
1.29k
            igraph_local_efficiency(&graph, NULL, &v, igraph_vss_all(), IGRAPH_DIRECTED, IGRAPH_OUT);
72
1.29k
            igraph_transitivity_undirected(&graph, &r, IGRAPH_TRANSITIVITY_NAN);
73
1.29k
            igraph_transitivity_local_undirected(&graph, &v, igraph_vss_all(), IGRAPH_TRANSITIVITY_NAN);
74
1.29k
            igraph_transitivity_avglocal_undirected(&graph, &r, IGRAPH_TRANSITIVITY_ZERO);
75
1.29k
            igraph_count_adjacent_triangles(&graph, &v, igraph_vss_all());
76
1.29k
            igraph_pagerank(&graph, NULL, &v, &r, 0.6, IGRAPH_DIRECTED, igraph_vss_all(), IGRAPH_PAGERANK_ALGO_PRPACK,
77
1.29k
                            NULL);
78
1.29k
            igraph_constraint(&graph, &v, igraph_vss_all(), NULL);
79
1.29k
            igraph_spanner(&graph, &iv, 2.34, NULL);
80
81
1.29k
            igraph_to_undirected(&graph, IGRAPH_TO_UNDIRECTED_COLLAPSE, NULL);
82
1.29k
            igraph_simplify(&graph, /* remove_multiple */ true, /* remove_loops */ false, NULL);
83
1.29k
            igraph_trussness(&graph, &iv);
84
85
1.29k
            igraph_vector_int_destroy(&iv);
86
1.29k
            igraph_vector_destroy(&v);
87
1.29k
        }
88
89
1.32k
        igraph_destroy(&graph);
90
1.32k
    }
91
92
1.32k
    igraph_vector_int_destroy(&edges);
93
94
1.32k
    IGRAPH_ASSERT(IGRAPH_FINALLY_STACK_EMPTY);
95
96
1.32k
    return 0;  // Non-zero return values are reserved for future use.
97
1.32k
}