Coverage Report

Created: 2025-07-14 06:15

/src/qpdf/libqpdf/Pl_Count.cc
Line
Count
Source (jump to first uncovered line)
1
#include <qpdf/Pl_Count.hh>
2
3
#include <qpdf/QIntC.hh>
4
5
class Pl_Count::Members
6
{
7
  public:
8
3.03k
    Members() = default;
9
    Members(Members const&) = delete;
10
    ~Members() = default;
11
12
    // Must be qpdf_offset_t, not size_t, to handle writing more than size_t can handle.
13
    qpdf_offset_t count{0};
14
    unsigned char last_char{'\0'};
15
};
16
17
Pl_Count::Pl_Count(char const* identifier, Pipeline* next) :
18
3.03k
    Pipeline(identifier, next),
19
3.03k
    m(std::make_unique<Members>())
20
3.03k
{
21
3.03k
    if (!next) {
22
0
        throw std::logic_error("Attempt to create Pl_Count with nullptr as next");
23
0
    }
24
3.03k
}
25
26
Pl_Count::~Pl_Count() // NOLINT (modernize-use-equals-default)
27
3.03k
{
28
    // Must be explicit and not inline -- see QPDF_DLL_CLASS in README-maintainer
29
3.03k
}
30
31
void
32
Pl_Count::write(unsigned char const* buf, size_t len)
33
6.02k
{
34
6.02k
    if (len) {
35
5.95k
        m->count += QIntC::to_offset(len);
36
5.95k
        m->last_char = buf[len - 1];
37
5.95k
        next()->write(buf, len);
38
5.95k
    }
39
6.02k
}
40
41
void
42
Pl_Count::finish()
43
2.77k
{
44
2.77k
    next()->finish();
45
2.77k
}
46
47
qpdf_offset_t
48
Pl_Count::getCount() const
49
2.77k
{
50
2.77k
    return m->count;
51
2.77k
}
52
53
unsigned char
54
Pl_Count::getLastChar() const
55
0
{
56
0
    return m->last_char;
57
0
}