diff options
Diffstat (limited to 'source/fud_assert.cpp')
-rw-r--r-- | source/fud_assert.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/source/fud_assert.cpp b/source/fud_assert.cpp index 749aa6b..14bf5eb 100644 --- a/source/fud_assert.cpp +++ b/source/fud_assert.cpp @@ -1,24 +1,20 @@ #include "fud_assert.hpp" #include "fud_array.hpp" +#include "fud_span.hpp" #include "fud_string_view.hpp" #include <climits> #include <cstdio> #include <format> -#include <stdexcept> namespace fud { -[[noreturn]] void assertFail(const char* assertion, const std::source_location sourceLocation) +void assertFormat( + const char* assertion, + const std::source_location sourceLocation, + Span<char, ASSERT_MSG_SIZE> buffer) { - constexpr size_t MAX_FILE_CHARS = 256; - constexpr size_t MAX_FUNCTION_CHARS = 256; - constexpr size_t BITS_PER_OCTAL = 3; - constexpr auto MAX_LINE_CHARS = BITS_PER_OCTAL * sizeof(decltype(sourceLocation.line())) + 3; - constexpr size_t MAX_ASSERT_CHARS = 512 - MAX_LINE_CHARS; - constexpr size_t ASSERT_MSG_SIZE = MAX_FILE_CHARS + MAX_LINE_CHARS + MAX_FUNCTION_CHARS + MAX_ASSERT_CHARS; - auto lengthResult = cStringLength(sourceLocation.file_name()); size_t filenameLength = 0; auto badLength = lengthResult < 1 || lengthResult > SSIZE_MAX; @@ -36,7 +32,6 @@ namespace fud { filenameLength = MAX_FILE_CHARS; } - Array<char, ASSERT_MSG_SIZE> buffer{}; // clang-format off static_cast<void>(std::format_to_n( buffer.data(), buffer.size() - 1U, @@ -46,6 +41,12 @@ namespace fud { sourceLocation.function_name(), MAX_FUNCTION_CHARS, assertion, MAX_ASSERT_CHARS)); // clang-format on +} + +[[noreturn]] void assertFail(const char* assertion, const std::source_location sourceLocation) +{ + Array<char, ASSERT_MSG_SIZE> buffer{}; + assertFormat(assertion, sourceLocation, Span<char, ASSERT_MSG_SIZE>::make(buffer)); buffer[buffer.size() - 1] = '\0'; fputs(buffer.data(), stderr); std::abort(); |