Coverage Report

Created: 2026-05-30 06:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qpdf/libqpdf/QPDFExc.cc
Line
Count
Source
1
#include <qpdf/QPDFExc.hh>
2
3
QPDFExc::QPDFExc(
4
    qpdf_error_code_e error_code,
5
    std::string const& filename,
6
    std::string const& object,
7
    qpdf_offset_t offset,
8
    std::string const& message) :
9
395k
    std::runtime_error(createWhat(filename, object, (offset ? offset : -1), message)),
10
395k
    error_code(error_code),
11
395k
    filename(filename),
12
395k
    object(object),
13
395k
    offset(offset ? offset : -1),
14
395k
    message(message)
15
395k
{
16
395k
}
17
18
QPDFExc::QPDFExc(
19
    qpdf_error_code_e error_code,
20
    std::string const& filename,
21
    std::string const& object,
22
    qpdf_offset_t offset,
23
    std::string const& message,
24
    bool zero_offset_valid) :
25
302k
    std::runtime_error(
26
302k
        createWhat(filename, object, (offset || zero_offset_valid ? offset : -1), message)),
27
302k
    error_code(error_code),
28
302k
    filename(filename),
29
302k
    object(object),
30
302k
    offset(offset || zero_offset_valid ? offset : -1),
31
302k
    message(message)
32
302k
{
33
302k
}
34
35
std::string
36
QPDFExc::createWhat(
37
    std::string const& filename,
38
    std::string const& object,
39
    qpdf_offset_t offset,
40
    std::string const& message)
41
698k
{
42
698k
    std::string result;
43
698k
    if (!filename.empty()) {
44
640k
        result += filename;
45
640k
    }
46
698k
    if (!(object.empty() && offset < 0)) {
47
609k
        if (!filename.empty()) {
48
552k
            result += " (";
49
552k
        }
50
609k
        if (!object.empty()) {
51
558k
            result += object;
52
558k
            if (offset >= 0) {
53
501k
                result += ", ";
54
501k
            }
55
558k
        }
56
609k
        if (offset >= 0) {
57
552k
            result += "offset " + std::to_string(offset);
58
552k
        }
59
609k
        if (!filename.empty()) {
60
552k
            result += ")";
61
552k
        }
62
609k
    }
63
698k
    if (!result.empty()) {
64
697k
        result += ": ";
65
697k
    }
66
698k
    result += message;
67
698k
    return result;
68
698k
}
69
70
qpdf_error_code_e
71
QPDFExc::getErrorCode() const
72
0
{
73
0
    return this->error_code;
74
0
}
75
76
std::string const&
77
QPDFExc::getFilename() const
78
0
{
79
0
    return this->filename;
80
0
}
81
82
std::string const&
83
QPDFExc::getObject() const
84
0
{
85
0
    return this->object;
86
0
}
87
88
qpdf_offset_t
89
QPDFExc::getFilePosition() const
90
0
{
91
0
    return offset < 0 ? 0 : offset;
92
0
}
93
94
std::string const&
95
QPDFExc::getMessageDetail() const
96
0
{
97
0
    return this->message;
98
0
}