Coverage Report

Created: 2026-10-17 06:37

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
11.1k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
12
11.1k
    if (Size < 2) return 0;
13
    
14
11.1k
    FuzzedDataProvider fdp(Data, Size);
15
    
16
    // Use part of the data for SMARTS pattern
17
11.1k
    std::string smarts_pattern = fdp.ConsumeRandomLengthString();
18
    
19
    // Use the rest for a SMILES molecule
20
11.1k
    std::string smiles = fdp.ConsumeRemainingBytesAsString();
21
    
22
11.1k
    if (smarts_pattern.empty() || smiles.empty()) return 0;
23
24
11.0k
    OpenBabel::obErrorLog.StopLogging();
25
26
11.0k
    OpenBabel::OBMol mol;
27
11.0k
    OpenBabel::OBConversion conv;
28
11.0k
    if (conv.SetInFormat("SMILES")) {
29
11.0k
        if (conv.ReadString(&mol, smiles)) {
30
8.57k
            OpenBabel::OBSmartsPattern sp;
31
8.57k
            if (sp.Init(smarts_pattern)) {
32
4.11k
                sp.Match(mol);
33
4.11k
            }
34
8.57k
        }
35
11.0k
    }
36
37
11.0k
    return 0;
38
11.1k
}