Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Checks: >
-google-readability-todo,
-google-readability-namespace-comments,
-google-runtime-references,
-misc-include-cleaner,
-misc-non-private-member-variables-in-classes,
-misc-unused-parameters,
-misc-no-recursion,
Expand All @@ -21,6 +22,7 @@ Checks: >
-modernize-avoid-c-arrays,
-modernize-use-auto,
-modernize-use-nodiscard,
-performance-enum-size,
-performance-move-const-arg,
-readability-braces-around-statements,
-readability-identifier-length,
Expand Down
1 change: 1 addition & 0 deletions .cppcheck-suppress
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ unusedFunction
useStlAlgorithm
noExplicitConstructor
unusedStructMember
normalCheckLevelMaxBranches
*:*_deps/*
2 changes: 1 addition & 1 deletion .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
clang_tidy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
build_and_lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
Expand All @@ -23,7 +23,7 @@ jobs:
- name: Install deps
run: sudo apt install cppcheck ccache

- uses: actions/cache@v3.3.1
- uses: actions/cache@v4
id: ccache-persistence
with:
path: ~/.ccache
Expand Down
2 changes: 1 addition & 1 deletion cmake/clang_format.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ add_custom_target(
clang-tidy
COMMAND ${PROJECT_SOURCE_DIR}/tools/run-clang-tidy.py
-p . -use-color -header-filter='.*' -quiet
-extra-arg=-std=c++17
-extra-arg=-std=c++17 -extra-arg=-Wno-unknown-warning-option
-ignore ${PROJECT_SOURCE_DIR}/.clang-tidy-ignore
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
USES_TERMINAL
Expand Down
4 changes: 3 additions & 1 deletion examples/ulog_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

using namespace std::chrono_literals;

static uint64_t currentTimeUs()
namespace {
uint64_t currentTimeUs()
{
return std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::steady_clock::now().time_since_epoch())
.count();
}
} // namespace

struct MyData {
uint64_t timestamp;
Expand Down
8 changes: 5 additions & 3 deletions test/ulog_parsing_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ TEST_CASE("ULog parsing - basic test: write then read")
}
}

static void readFileWriteTest(const std::filesystem::path& path,
const std::function<unsigned()>& next_chunk_size)
namespace {
void readFileWriteTest(const std::filesystem::path& path,
const std::function<unsigned()>& next_chunk_size)
{
FILE* file = fopen(path.c_str(), "rb");
CHECK(file);
Expand Down Expand Up @@ -144,6 +145,7 @@ static void readFileWriteTest(const std::filesystem::path& path,
CHECK_EQ(input_data.size(), written_data.size());
CHECK_EQ(input_data, written_data);
}
} // namespace

TEST_CASE("ULog parsing - read sample files then write")
{
Expand Down Expand Up @@ -343,7 +345,7 @@ TEST_CASE("ULog parsing - simple writer")
std::vector<MyData> written_data_messages;
for (int i = 0; i < 100; ++i) {
MyData data{};
data.timestamp = i * 1000;
data.timestamp = static_cast<uint64_t>(i) * 1000;
data.cpuload = cpuload;
data.counter = i;
writer.writeData(my_data_msg_id, data);
Expand Down
18 changes: 9 additions & 9 deletions ulog_cpp/data_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ void DataContainer::headerComplete()

// try to resolve all fields for params
for (auto& it : _default_parameters) {
auto& parameter = it.second;
parameter.field().resolveDefinition(_message_formats, 0);
auto& parameter_value = it.second;
parameter_value.field().resolveDefinition(_message_formats, 0);
}

for (auto& it : _initial_parameters) {
auto& parameter = it.second;
parameter.field().resolveDefinition(_message_formats, 0);
auto& parameter_value = it.second;
parameter_value.field().resolveDefinition(_message_formats, 0);
}

for (auto& parameter : _changed_parameters) {
parameter.field().resolveDefinition(_message_formats, 0);
for (auto& parameter_value : _changed_parameters) {
parameter_value.field().resolveDefinition(_message_formats, 0);
}

_header_complete = true;
Expand Down Expand Up @@ -100,10 +100,10 @@ void DataContainer::parameter(const Parameter& parameter_arg)
return;
}
if (_header_complete) {
auto parameter = parameter_arg;
auto parameter_value = parameter_arg;
// if header is complete, we can resolve definition here
parameter.field().resolveDefinition(_message_formats, 0);
_changed_parameters.push_back(parameter);
parameter_value.field().resolveDefinition(_message_formats, 0);
_changed_parameters.push_back(parameter_value);
} else {
_initial_parameters.insert({parameter_arg.field().name(), parameter_arg});
}
Expand Down
6 changes: 3 additions & 3 deletions ulog_cpp/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ Value::NativeTypeVariant Value::asNativeTypeVariant() const
if (_field_ref.arrayLength() == -1 || _array_index >= 0) {
// decode as a single value. Either it is a single value,
// or the user has explicitly selected an array element
int array_offset = _array_index >= 0 ? _array_index : 0;
const int array_offset = _array_index >= 0 ? _array_index : 0;
switch (_field_ref.type().type) {
case Field::BasicType::INT8:
return deserialize<int8_t>(_backing_ref_begin, _backing_ref_end,
Expand Down Expand Up @@ -298,8 +298,8 @@ Value Value::operator[](const Field& field) const
if (!_field_ref.definitionResolved()) {
throw AccessException("Cannot access field of unresolved type");
}
int submessage_offset = _field_ref.offsetInMessage() +
((_array_index >= 0) ? _field_ref.type().size * _array_index : 0);
const int submessage_offset = _field_ref.offsetInMessage() +
((_array_index >= 0) ? _field_ref.type().size * _array_index : 0);

return Value(field, _backing_ref_begin + submessage_offset, _backing_ref_end);
}
Expand Down
30 changes: 20 additions & 10 deletions ulog_cpp/messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,25 +172,25 @@ class Field {
* @brief Get the type attributes of the field
* @return The type attributes
*/
inline const TypeAttributes& type() const { return _type; }
const TypeAttributes& type() const { return _type; }

/**
* @brief Get the array length of the field
* @return The array length, -1 if not an array
*/
inline int arrayLength() const { return _array_length; }
int arrayLength() const { return _array_length; }

/**
* @brief Get the offset of the field in the message. This is only valid if the field is resolved.
* @return The offset in bytes, -1 if not resolved
*/
inline int offsetInMessage() const { return _offset_in_message_bytes; }
int offsetInMessage() const { return _offset_in_message_bytes; }

/**
* @brief Get the name of the field
* @return The name
*/
inline const std::string& name() const { return _name; }
const std::string& name() const { return _name; }

/**
* @brief Get the size of the field in bytes. This is only valid if the field is resolved.
Expand All @@ -203,11 +203,11 @@ class Field {
* is defined and the type is not nested or the nested message is resolved.
* @return True if the field is resolved
*/
inline bool definitionResolved() const
bool definitionResolved() const
{
return _offset_in_message_bytes >= 0 &&
(_type.type != BasicType::NESTED || _type.nested_message != nullptr);
};
}

/**
* @brief Attempt to resolve the definition of the field.
Expand Down Expand Up @@ -353,8 +353,8 @@ class Value {
// this is natively a vector
if constexpr (is_vector<ReturnType>::value) {
// return type is also vector
if constexpr (std::is_same<typename NativeType::value_type,
typename ReturnType::value_type>::value) {
if constexpr (std::is_same_v<typename NativeType::value_type,
typename ReturnType::value_type>) {
// return type is same as native type
res = arg;
} else {
Expand Down Expand Up @@ -428,13 +428,22 @@ class Value {
int array_offset)
{
T v;
int total_offset = offset + array_offset * sizeof(T);
const int total_offset = offset + (array_offset * sizeof(T));
if (backing_start > backing_end ||
backing_end - backing_start - total_offset < static_cast<int64_t>(sizeof(v))) {
backing_end - backing_start < static_cast<int64_t>(sizeof(v)) + total_offset) {
throw AccessException("Unexpected data type size");
}
// GCC 14.2 raises an error here when building with -fsanitize=address
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
#pragma GCC diagnostic ignored "-Wstringop-overflow"
#endif
std::copy(backing_start + total_offset, backing_start + total_offset + sizeof(v),
reinterpret_cast<uint8_t*>(&v));
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
return v;
}

Expand Down Expand Up @@ -594,6 +603,7 @@ class MessageFormat {
std::vector<std::string> fieldNames() const
{
std::vector<std::string> names;
names.reserve(_fields_ordered.size());
for (const auto& field_it : _fields_ordered) {
names.push_back(field_it->name());
}
Expand Down
2 changes: 1 addition & 1 deletion ulog_cpp/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "raw_messages.hpp"

#if 0
#if 0 // NOLINT (readability-avoid-unconditional-preprocessor-if)
#define DBG_PRINTF(...) printf(__VA_ARGS__)
#else
#define DBG_PRINTF(...)
Expand Down
8 changes: 8 additions & 0 deletions ulog_cpp/simple_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@

#include <cstdio>
#include <memory>
// GCC 14.2 raises an error in <regex> when building with -fsanitize=address
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
#include <regex>
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#include <unordered_map>
#include <vector>

Expand Down
Loading