Coverage Report

Created: 2026-10-28 07:06

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