Coverage Report

Created: 2026-01-09 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qpdf/libqpdf/BitWriter.cc
Line
Count
Source
1
#include <qpdf/BitWriter.hh>
2
3
// See comments in bits_functions.hh
4
#define BITS_WRITE 1
5
#include <qpdf/bits_functions.hh>
6
7
BitWriter::BitWriter(Pipeline* pl) :
8
9.67k
    pl(pl)
9
9.67k
{
10
9.67k
}
11
12
void
13
BitWriter::writeBits(unsigned long long val, size_t bits)
14
1.74M
{
15
1.74M
    write_bits(this->ch, this->bit_offset, val, bits, this->pl);
16
1.74M
}
17
18
void
19
BitWriter::writeBitsSigned(long long val, size_t bits)
20
1.25M
{
21
1.25M
    unsigned long long uval = 0;
22
1.25M
    if (val < 0) {
23
1.15M
        uval = (1ULL << bits) + static_cast<unsigned long long>(val);
24
1.15M
    } else {
25
107k
        uval = static_cast<unsigned long long>(val);
26
107k
    }
27
1.25M
    writeBits(uval, bits);
28
1.25M
}
29
30
void
31
BitWriter::writeBitsInt(int val, size_t bits)
32
136k
{
33
136k
    writeBits(static_cast<unsigned long long>(val), bits);
34
136k
}
35
36
void
37
BitWriter::flush()
38
81.6k
{
39
81.6k
    if (bit_offset < 7) {
40
15.5k
        size_t bits_to_write = bit_offset + 1;
41
15.5k
        write_bits(this->ch, this->bit_offset, 0, bits_to_write, this->pl);
42
15.5k
    }
43
81.6k
}