summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-10-02 19:51:41 -0500
committerDominick Allen <djallen@librehumanitas.org>2024-10-02 19:51:41 -0500
commitf7eede23de6f78b2b33b477b2b4c5451141825d5 (patch)
treed698a92272b8e4a8428b82d9a21f3e98ed267a6d /include
parent32c722d50943bbdeba65a77d5e94f8692cf75f3c (diff)
Add setup for coverage and cppcheck.
Diffstat (limited to 'include')
-rw-r--r--include/fud_assert.hpp2
-rw-r--r--include/fud_c_file.hpp2
-rw-r--r--include/fud_memory.hpp6
-rw-r--r--include/fud_utf8.hpp11
-rw-r--r--include/libfud.hpp9
5 files changed, 20 insertions, 10 deletions
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<bool>(expr) ? static_cast<void>(0) : assertFail(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__))
+ ((expr) ? static_cast<void>(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<Derived&>(*this);
+ const auto& self = static_cast<const Derived&>(*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<uint8_t*>(&destination)[idx] = reinterpret_cast<const uint8_t*>(&source)[idx];
+ reinterpret_cast<char*>(&destination)[idx] = reinterpret_cast<const char*>(&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<U>(rhs)};
+
int difference = 0;
for (size_t idx = 0; idx < Count; ++idx) {
// NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast)
difference = reinterpret_cast<const uint8_t*>(&lhs)[idx] -
- reinterpret_cast<const uint8_t*>(&std::forward<U>(rhs))[idx];
+ reinterpret_cast<const uint8_t*>(&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<utf8, 1> 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<utf8, 4>& data)
+ static constexpr FudUtf8 makeUtf8(const Array<utf8, 4>& 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<String, FudStatus> getEnv(const char* name);
template<typename T>