summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2025-03-31 08:33:08 -0500
committerDominick Allen <djallen@librehumanitas.org>2025-03-31 08:33:08 -0500
commit8b0bc70db73b48d833a3b5791e55921768cf6932 (patch)
tree862ae34933a7fc9f480038d974f59d7683a82605 /source
parentc426110f24516f92ecb8a5374e2a281f2c79787a (diff)
Remove reinterpret_cast usage in favor of std::bit_cast.
Diffstat (limited to 'source')
-rw-r--r--source/fud_assert.cpp2
-rw-r--r--source/fud_file.cpp8
-rw-r--r--source/fud_print.cpp3
-rw-r--r--source/fud_sqlite.cpp3
-rw-r--r--source/fud_string.cpp7
5 files changed, 9 insertions, 14 deletions
diff --git a/source/fud_assert.cpp b/source/fud_assert.cpp
index 425826d..64b3275 100644
--- a/source/fud_assert.cpp
+++ b/source/fud_assert.cpp
@@ -42,7 +42,7 @@ DrainResult StdErrSink::drain(StringView source)
return result;
}
/* TODO: give users control over this functionality */
- result.bytesDrained = fwrite(reinterpret_cast<const char*>(source.m_data), 1, source.m_length, stderr);
+ result.bytesDrained = fwrite(std::bit_cast<const char*>(source.m_data), 1, source.m_length, stderr);
if (result.bytesDrained != source.m_length) {
result.status = FudStatus::Full;
}
diff --git a/source/fud_file.cpp b/source/fud_file.cpp
index 7219638..9666b14 100644
--- a/source/fud_file.cpp
+++ b/source/fud_file.cpp
@@ -728,8 +728,7 @@ DrainResult BufferedRegularFile::readUtf8(Utf8& sink, Option<size_t> maxExtraAtt
{
size_t extraAttempts{maxExtraAttempts.valueOr(0)};
Array<utf8, 4> utf8Data{};
- // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
- auto drainResult = read(reinterpret_cast<std::byte*>(utf8Data.data()), 1, maxExtraAttempts);
+ auto drainResult = read(std::bit_cast<std::byte*>(utf8Data.data()), 1, maxExtraAttempts);
if (drainResult.status != FudStatus::Success) {
return drainResult;
}
@@ -756,8 +755,7 @@ DrainResult BufferedRegularFile::readUtf8(Utf8& sink, Option<size_t> maxExtraAtt
}
if (bytesToRead > 0) {
- // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
- auto utf8ReadResult = read(reinterpret_cast<std::byte*>(utf8Data.data() + 1), bytesToRead, extraAttempts);
+ auto utf8ReadResult = read(std::bit_cast<std::byte*>(utf8Data.data() + 1), bytesToRead, extraAttempts);
drainResult.status = utf8ReadResult.status;
drainResult.bytesDrained += utf8ReadResult.bytesDrained;
}
@@ -784,7 +782,7 @@ void BufferedRegularFile::drainReadBuffer(std::byte*& sink, size_t& length, Drai
}
}
-// NOLINTNEXTLINE(readability-convert-member-functions-to-static,cppcoreguidelines-rvalue-*)
+// NOLINTNEXTLINE(cppcoreguidelines-rvalue-*)
FudStatus BufferedRegularFile::setBuffer(Vector<std::byte>&& buffer, bool discardOldBuffer)
{
static_cast<void>(buffer);
diff --git a/source/fud_print.cpp b/source/fud_print.cpp
index 85a3d76..6b7bac1 100644
--- a/source/fud_print.cpp
+++ b/source/fud_print.cpp
@@ -20,7 +20,6 @@
#include "fud_string_view.hpp"
#include <cstdio>
-#include <exception>
namespace fud {
@@ -36,7 +35,7 @@ DrainResult StdOutSink::drain(StringView source)
return result;
}
/* TODO: give users control over this functionality */
- result.bytesDrained = fwrite(reinterpret_cast<const char*>(source.m_data), 1, source.m_length, stdout);
+ result.bytesDrained = fwrite(std::bit_cast<const char*>(source.m_data), 1, source.m_length, stdout);
if (result.bytesDrained != source.m_length) {
result.status = FudStatus::Full;
}
diff --git a/source/fud_sqlite.cpp b/source/fud_sqlite.cpp
index fccbc1e..c607b37 100644
--- a/source/fud_sqlite.cpp
+++ b/source/fud_sqlite.cpp
@@ -264,8 +264,7 @@ Result<StringView, FudStatus> SqliteDb::columnText(SqliteStatement& statement, i
}
output.m_length = static_cast<size_t>(outputLength);
- // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
- output.m_data = reinterpret_cast<const utf8*>(sqlite3_column_text(statement.statement(), index));
+ output.m_data = std::bit_cast<const utf8*>(sqlite3_column_text(statement.statement(), index));
if (output.m_data == nullptr && output.m_length != 0) {
return Error{FudStatus::Failure};
}
diff --git a/source/fud_string.cpp b/source/fud_string.cpp
index 777212d..d4fd691 100644
--- a/source/fud_string.cpp
+++ b/source/fud_string.cpp
@@ -241,9 +241,9 @@ String& String::operator=(String&& rhs) noexcept
void String::cleanup()
{
- const auto* allocPtr = allocator();
+ auto* allocPtr = allocator();
if (isLarge() && m_repr.large.data != nullptr && allocPtr != nullptr) {
- allocator()->deallocate(std::bit_cast<std::byte*>(m_repr.large.data), m_repr.large.capacity);
+ allocPtr->deallocate(std::bit_cast<std::byte*>(m_repr.large.data), m_repr.large.capacity);
m_repr.large.data = nullptr;
}
}
@@ -816,8 +816,7 @@ FudStatus String::makeLarge(size_t cap, size_t len, utf8*& outputData)
if (dataResult.isError()) {
return dataResult.getError();
}
- // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
- m_repr.large.data = reinterpret_cast<utf8*>(dataResult.getOkay());
+ m_repr.large.data = std::bit_cast<utf8*>(dataResult.getOkay());
outputData = m_repr.large.data;
setLarge();
return FudStatus::Success;