From 8249b28bea29e8ce17eac12776a60ec3f9e47176 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Thu, 17 Oct 2024 19:42:29 -0500 Subject: Rename InvalidInput to ArgumentInvalid. --- source/fud_assert.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'source/fud_assert.cpp') 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 #include #include -#include namespace fud { -[[noreturn]] void assertFail(const char* assertion, const std::source_location sourceLocation) +void assertFormat( + const char* assertion, + const std::source_location sourceLocation, + Span 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 buffer{}; // clang-format off static_cast(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 buffer{}; + assertFormat(assertion, sourceLocation, Span::make(buffer)); buffer[buffer.size() - 1] = '\0'; fputs(buffer.data(), stderr); std::abort(); -- cgit v1.2.3