Coverage Report

Created: 2026-08-13 07:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openbabel/test/fuzz/fuzz_smart.cpp
Line
Count
Source
1
#include <openbabel/babelconfig.h>
2
#include <openbabel/mol.h>
3
#include <openbabel/parsmart.h>
4
#include <openbabel/obconversion.h>
5
6
// Vendored alongside this file (LLVM Apache-2.0 WITH LLVM-exception)
7
// so the harness compiles outside of an LLVM/libfuzzer toolchain — in
8
// particular under GCC, where the libfuzzer headers aren't shipped.
9
#include "FuzzedDataProvider.h"
10
11
10.0k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
12
10.0k
    if (Size < 2) return 0;
13
    
14
10.0k
    FuzzedDataProvider fdp(Data, Size);
15
    
16
    // Use part of the data for SMARTS pattern
17
10.0k
    std::string smarts_pattern = fdp.ConsumeRandomLengthString();
18
    
19
    // Use the rest for a SMILES molecule
20
10.0k
    std::string smiles = fdp.ConsumeRemainingBytesAsString();
21
    
22
10.0k
    if (smarts_pattern.empty() || smiles.empty()) return 0;
23
24
10.0k
    OpenBabel::obErrorLog.StopLogging();
25
26
10.0k
    OpenBabel::OBMol mol;
27
10.0k
    OpenBabel::OBConversion conv;
28
10.0k
    if (conv.SetInFormat("SMILES")) {
29
10.0k
        if (conv.ReadString(&mol, smiles)) {
30
7.62k
            OpenBabel::OBSmartsPattern sp;
31
7.62k
            if (sp.Init(smarts_pattern)) {
32
3.55k
                sp.Match(mol);
33
3.55k
            }
34
7.62k
        }
35
10.0k
    }
36
37
10.0k
    return 0;
38
10.0k
}