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

mavlink / MAVSDK / 16665088909

01 Aug 2025 02:55AM UTC coverage: 46.166% (-0.1%) from 46.31%
16665088909

push

github

web-flow
Merge pull request #2630 from mavlink/pr-segfault-fixes

Stack-use-after-free and thread-safety fixes, CI additions, clang-format-19

241 of 320 new or added lines in 32 files covered. (75.31%)

39 existing lines in 10 files now uncovered.

16101 of 34876 relevant lines covered (46.17%)

361.1 hits per line

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

72.73
/src/mavsdk/core/log.cpp
1
#include "log.h"
2
#include "unused.h"
3

4
#include <mutex>
5

6
#if defined(WINDOWS)
7
#include <windows.h>
8
#define WIN_COLOR_RED 4
9
#define WIN_COLOR_GREEN 10
10
#define WIN_COLOR_YELLOW 14
11
#define WIN_COLOR_BLUE 1
12
#define WIN_COLOR_GRAY 8
13
#define WIN_COLOR_RESET 7
14
#else
15
#define ANSI_COLOR_RED "\x1b[31m"
16
#define ANSI_COLOR_GREEN "\x1b[32m"
17
#define ANSI_COLOR_YELLOW "\x1b[33m"
18
#define ANSI_COLOR_BLUE "\x1b[34m"
19
#define ANSI_COLOR_GRAY "\x1b[37m"
20
#define ANSI_COLOR_RESET "\x1b[0m"
21
#endif
22

23
namespace mavsdk {
24

25
static std::mutex callback_mutex_{};
26
static log::Callback callback_{nullptr};
27

28
// Dedicated mutex for logging operations - moved from header to avoid inlining issues
29
static std::mutex log_mutex_{};
30

31
std::mutex& get_log_mutex()
1,578✔
32
{
33
    return log_mutex_;
1,578✔
34
}
35

UNCOV
36
std::ostream& operator<<(std::ostream& os, std::byte b)
×
37
{
38
    return os << std::bitset<8>(std::to_integer<int>(b));
×
39
}
40

41
log::Callback& log::get_callback()
1,578✔
42
{
43
    std::lock_guard<std::mutex> lock(callback_mutex_);
1,578✔
44
    return callback_;
3,156✔
45
}
1,578✔
46

47
void log::subscribe(const log::Callback& callback)
×
48
{
49
    std::lock_guard<std::mutex> lock(callback_mutex_);
×
50
    callback_ = callback;
×
51
}
×
52

53
void set_color(Color color)
3,156✔
54
{
55
#if defined(WINDOWS)
56
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
57
    switch (color) {
58
        case Color::Red:
59
            SetConsoleTextAttribute(handle, WIN_COLOR_RED);
60
            break;
61
        case Color::Green:
62
            SetConsoleTextAttribute(handle, WIN_COLOR_GREEN);
63
            break;
64
        case Color::Yellow:
65
            SetConsoleTextAttribute(handle, WIN_COLOR_YELLOW);
66
            break;
67
        case Color::Blue:
68
            SetConsoleTextAttribute(handle, WIN_COLOR_BLUE);
69
            break;
70
        case Color::Gray:
71
            SetConsoleTextAttribute(handle, WIN_COLOR_GRAY);
72
            break;
73
        case Color::Reset:
74
            SetConsoleTextAttribute(handle, WIN_COLOR_RESET);
75
            break;
76
    }
77
#elif defined(ANDROID) || defined(IOS)
78
    UNUSED(color);
79
#else
80
    switch (color) {
3,156✔
81
        case Color::Red:
53✔
82
            std::cout << ANSI_COLOR_RED;
53✔
83
            break;
53✔
84
        case Color::Green:
1,119✔
85
            std::cout << ANSI_COLOR_GREEN;
1,119✔
86
            break;
1,119✔
87
        case Color::Yellow:
210✔
88
            std::cout << ANSI_COLOR_YELLOW;
210✔
89
            break;
210✔
90
        case Color::Blue:
196✔
91
            std::cout << ANSI_COLOR_BLUE;
196✔
92
            break;
196✔
93
        case Color::Gray:
×
94
            std::cout << ANSI_COLOR_GRAY;
×
95
            break;
×
96
        case Color::Reset:
1,578✔
97
            std::cout << ANSI_COLOR_RESET;
1,578✔
98
            break;
1,578✔
99
    }
100
#endif
101
}
3,156✔
102

103
} // namespace mavsdk
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