Coverage Report

Created: 2025-11-24 06:49

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
1.64k
    pl(pl)
9
1.64k
{
10
1.64k
}
11
12
void
13
BitWriter::writeBits(unsigned long long val, size_t bits)
14
370k
{
15
370k
    write_bits(this->ch, this->bit_offset, val, bits, this->pl);
16
370k
}
17
18
void
19
BitWriter::writeBitsSigned(long long val, size_t bits)
20
370k
{
21
370k
    unsigned long long uval = 0;
22
370k
    if (val < 0) {
23
11.0k
        uval = (1ULL << bits) + static_cast<unsigned long long>(val);
24
359k
    } else {
25
359k
        uval = static_cast<unsigned long long>(val);
26
359k
    }
27
370k
    writeBits(uval, bits);
28
370k
}
29
30
void
31
BitWriter::writeBitsInt(int val, size_t bits)
32
0
{
33
0
    writeBits(static_cast<unsigned long long>(val), bits);
34
0
}
35
36
void
37
BitWriter::flush()
38
1.63k
{
39
1.63k
    if (bit_offset < 7) {
40
1.02k
        size_t bits_to_write = bit_offset + 1;
41
1.02k
        write_bits(this->ch, this->bit_offset, 0, bits_to_write, this->pl);
42
1.02k
    }
43
1.63k
}