From f7eede23de6f78b2b33b477b2b4c5451141825d5 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Wed, 2 Oct 2024 19:51:41 -0500 Subject: Add setup for coverage and cppcheck. --- include/fud_assert.hpp | 2 +- include/fud_c_file.hpp | 2 +- include/fud_memory.hpp | 6 ++++-- include/fud_utf8.hpp | 11 +++++------ include/libfud.hpp | 9 +++++++++ 5 files changed, 20 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/fud_assert.hpp b/include/fud_assert.hpp index 5b63703..fd861ea 100644 --- a/include/fud_assert.hpp +++ b/include/fud_assert.hpp @@ -24,7 +24,7 @@ void assertFail(const char* assertion, const char* file, unsigned int line, cons __attribute__((__noreturn__)); #define fudAssert(expr) \ - (static_cast(expr) ? static_cast(0) : assertFail(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__)) + ((expr) ? static_cast(0) : assertFail(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__)) } // namespace fud diff --git a/include/fud_c_file.hpp b/include/fud_c_file.hpp index 3b7d821..0908841 100644 --- a/include/fud_c_file.hpp +++ b/include/fud_c_file.hpp @@ -151,7 +151,7 @@ class CFile { FILE* file() { - auto& self = static_cast(*this); + const auto& self = static_cast(*this); return self.m_file; } diff --git a/include/fud_memory.hpp b/include/fud_memory.hpp index 41393bd..62ff81a 100644 --- a/include/fud_memory.hpp +++ b/include/fud_memory.hpp @@ -77,7 +77,7 @@ void copyMem(T& destination, const U& source) for (size_t idx = 0; idx < Count; ++idx) { // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast) - reinterpret_cast(&destination)[idx] = reinterpret_cast(&source)[idx]; + reinterpret_cast(&destination)[idx] = reinterpret_cast(&source)[idx]; // NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast) } } @@ -115,11 +115,13 @@ int compareMem(const T& lhs, U&& rhs) static_assert(Count <= sizeof(T)); static_assert(Count <= sizeof(U)); + U uRhs{std::forward(rhs)}; + int difference = 0; for (size_t idx = 0; idx < Count; ++idx) { // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast) difference = reinterpret_cast(&lhs)[idx] - - reinterpret_cast(&std::forward(rhs))[idx]; + reinterpret_cast(&uRhs)[idx]; // NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast) if (difference != 0) { break; diff --git a/include/fud_utf8.hpp b/include/fud_utf8.hpp index 99766d4..5b84a3a 100644 --- a/include/fud_utf8.hpp +++ b/include/fud_utf8.hpp @@ -19,7 +19,6 @@ #define FUD_UTF8_HPP #include "fud_array.hpp" -#include "fud_memory.hpp" #include "fud_status.hpp" #include "fud_unique_array.hpp" @@ -62,7 +61,7 @@ constexpr bool validUtf8MB(utf8 code) noexcept struct Ascii { Array characters; - constexpr Ascii() noexcept = default; + constexpr Ascii() noexcept = default; // cppcheck-suppress uninitMemberVar constexpr explicit Ascii(utf8 chr) noexcept : characters{{chr}} { @@ -252,10 +251,10 @@ struct FudUtf8 { static constexpr Ascii invalidAsciiCode{Ascii{0xFF}}; static FudUtf8 fromString(const String& fudString, size_t index) noexcept; - static FudUtf8 fromStringView(StringView&& fudView, size_t index) noexcept; - static FudUtf8 fromStringView(const StringView& fudView, size_t index) noexcept; + static FudUtf8 fromStringView(StringView&& view, size_t index) noexcept; + static FudUtf8 fromStringView(const StringView& view, size_t index) noexcept; - static constexpr FudUtf8 makeUtf8(Array& data) + static constexpr FudUtf8 makeUtf8(const Array& data) { FudUtf8 unicode{}; if (Ascii::valid(data[0])) { @@ -367,10 +366,10 @@ struct FudUtf8 { [[nodiscard]] constexpr int64_t hash() const noexcept { - using fud::Utf8Type; using fud::Utf82Byte; using fud::Utf83Byte; using fud::Utf84Byte; + using fud::Utf8Type; if (!valid()) { return -1; diff --git a/include/libfud.hpp b/include/libfud.hpp index 1e6df5d..271d55b 100644 --- a/include/libfud.hpp +++ b/include/libfud.hpp @@ -27,6 +27,15 @@ namespace fud { /** \brief Fear, unknown, doubt. Call at your own peril. */ void fud(); +/** + * \brief Get an environmental variable if it exists. + * + * \param[in] name The name of the variable to look up. + * + * \retstmt The value of the string bound to the variable if it exists. + * \retcode FudStatus::NullPointer if name is a null pointer. + * \retcode FudStatus::NotFound if no binding for the variable exists. + */ Result getEnv(const char* name); template -- cgit v1.2.3