Coverage Report

Created: 2025-12-05 06:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openbabel/test/fuzz/fuzz_convert.cpp
Line
Count
Source
1
#include <openbabel/babelconfig.h>
2
#include <openbabel/mol.h>
3
#include <openbabel/obconversion.h>
4
#include <cstdlib>
5
#include <stdio.h>
6
#include <sstream>
7
8
#include <fuzzer/FuzzedDataProvider.h>
9
10
1
std::vector<std::string> getAllFormats() {
11
1
    std::vector<std::string> formats;
12
1
    OpenBabel::OBPlugin::ListAsVector("formats", "ids", formats);
13
1
    std::sort(formats.begin(), formats.end());
14
1
    return formats;
15
1
}
16
17
1.99k
const char *randomFormat(FuzzedDataProvider &fdp) {
18
1.99k
    static std::vector<std::string> formats = getAllFormats();
19
1.99k
    return formats[fdp.ConsumeIntegralInRange<int>(0, formats.size() - 1)].c_str();
20
1.99k
}
21
22
996
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
23
996
    using namespace OpenBabel;
24
996
    obErrorLog.StopLogging();
25
26
996
    FuzzedDataProvider fdp(Data, Size);
27
996
    OBConversion conv;
28
996
    conv.SetInFormat(randomFormat(fdp));
29
996
    conv.SetOutFormat(randomFormat(fdp));
30
31
996
    std::ostringstream outStream;
32
996
    std::istringstream inStream(fdp.ConsumeRandomLengthString());
33
34
996
    try {
35
996
        conv.Convert(&inStream, &outStream);
36
996
    } catch (...) {
37
        // no error handling
38
0
    }
39
40
996
    return 0;
41
996
}