• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

llnl / dftracer-utils / 28286012595

27 Jun 2026 10:04AM UTC coverage: 51.056% (-1.3%) from 52.356%
28286012595

Pull #79

github

web-flow
Merge 6c6535a19 into 8eb383f39
Pull Request #79: Add Valgrind memory checking (C++, Python, MPI) and fix the bugs it found

32079 of 80165 branches covered (40.02%)

Branch coverage included in aggregate %.

129 of 149 new or added lines in 11 files covered. (86.58%)

5116 existing lines in 181 files now uncovered.

32739 of 46790 relevant lines covered (69.97%)

9929.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/dftracer/utils/server/cursor.cpp
1
#include <dftracer/utils/server/cursor.h>
2

3
#include <array>
4
#include <cstring>
5

6
namespace dftracer::utils::server {
7

8
namespace {
9

10
// Minimal base64 encode/decode for cursor serialization.
11
static constexpr char BASE64_CHARS[] =
12
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
13

14
std::string base64_encode(const void* data, std::size_t len) {
×
15
    auto* bytes = static_cast<const unsigned char*>(data);
×
16
    std::string out;
×
17
    out.reserve(4 * ((len + 2) / 3));
×
18
    for (std::size_t i = 0; i < len; i += 3) {
×
19
        unsigned val = static_cast<unsigned>(bytes[i]) << 16;
×
20
        if (i + 1 < len) val |= static_cast<unsigned>(bytes[i + 1]) << 8;
×
21
        if (i + 2 < len) val |= static_cast<unsigned>(bytes[i + 2]);
×
22
        out.push_back(BASE64_CHARS[(val >> 18) & 0x3F]);
×
23
        out.push_back(BASE64_CHARS[(val >> 12) & 0x3F]);
×
24
        out.push_back((i + 1 < len) ? BASE64_CHARS[(val >> 6) & 0x3F] : '=');
×
25
        out.push_back((i + 2 < len) ? BASE64_CHARS[val & 0x3F] : '=');
×
UNCOV
26
    }
×
27
    return out;
×
28
}
×
29

30
std::optional<std::string> base64_decode(std::string_view sv) {
×
31
    static constexpr unsigned char DEC_TABLE[256] = {
32
        // clang-format off
33
        64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
34
        64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
35
        64,64,64,64,64,64,64,64,64,64,64,62,64,64,64,63,
36
        52,53,54,55,56,57,58,59,60,61,64,64,64,64,64,64,
37
        64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,
38
        15,16,17,18,19,20,21,22,23,24,25,64,64,64,64,64,
39
        64,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,
40
        41,42,43,44,45,46,47,48,49,50,51,64,64,64,64,64,
41
        64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
42
        64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
43
        64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
44
        64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
45
        64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
46
        64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
47
        64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
48
        64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
49
        // clang-format on
50
    };
51

52
    if (sv.size() % 4 != 0) return std::nullopt;
×
53
    std::string out;
×
54
    out.reserve(sv.size() / 4 * 3);
×
55
    for (std::size_t i = 0; i < sv.size(); i += 4) {
×
56
        auto a = DEC_TABLE[static_cast<unsigned char>(sv[i])];
×
57
        auto b = DEC_TABLE[static_cast<unsigned char>(sv[i + 1])];
×
58
        auto c = DEC_TABLE[static_cast<unsigned char>(sv[i + 2])];
×
59
        auto d = DEC_TABLE[static_cast<unsigned char>(sv[i + 3])];
×
60
        if (a == 64 || b == 64) return std::nullopt;
×
61
        unsigned val = (a << 18) | (b << 12);
×
62
        out.push_back(static_cast<char>(val >> 16));
×
63
        if (c != 64) {
×
64
            val |= (c << 6);
×
65
            out.push_back(static_cast<char>((val >> 8) & 0xFF));
×
UNCOV
66
        }
×
67
        if (d != 64) {
×
68
            val |= d;
×
69
            out.push_back(static_cast<char>(val & 0xFF));
×
UNCOV
70
        }
×
UNCOV
71
    }
×
72
    return out;
×
73
}
×
74

75
}  // namespace
76

77
// Wire format: 8 bytes file_index + 4 bytes chunk_index + 4 bytes line_offset
78
// (all little-endian), base64-encoded.
79
static constexpr std::size_t CURSOR_BYTES = 16;
80

81
std::string QueryCursor::encode() const {
×
82
    unsigned char raw[CURSOR_BYTES];
83
    std::memcpy(raw, &file_index, 8);
×
84
    std::memcpy(raw + 8, &chunk_index, 4);
×
85
    std::memcpy(raw + 12, &line_offset, 4);
×
86
    return base64_encode(raw, CURSOR_BYTES);
×
87
}
88

89
std::optional<QueryCursor> QueryCursor::decode(std::string_view cursor) {
×
90
    auto raw = base64_decode(cursor);
×
91
    if (!raw || raw->size() != CURSOR_BYTES) return std::nullopt;
×
92
    QueryCursor c;
×
93
    std::memcpy(&c.file_index, raw->data(), 8);
×
94
    std::memcpy(&c.chunk_index, raw->data() + 8, 4);
×
95
    std::memcpy(&c.line_offset, raw->data() + 12, 4);
×
96
    return c;
×
97
}
×
98

99
}  // namespace dftracer::utils::server
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc