diff options
author | Dominick Allen <djallen@librehumanitas.org> | 2025-01-02 21:57:57 -0600 |
---|---|---|
committer | Dominick Allen <djallen@librehumanitas.org> | 2025-01-02 21:57:57 -0600 |
commit | 1ac94c8aff47b549f30b370be2191bcc0157826c (patch) | |
tree | acca28e85989d5a4a3a340caa7a8c96065e01a90 /include | |
parent | d5a174a6d4f8be5e7cffe7c2adbb8db23b578f56 (diff) |
More bugs in format...
Diffstat (limited to 'include')
-rw-r--r-- | include/fud_format.hpp | 38 | ||||
-rw-r--r-- | include/fud_status.hpp | 1 |
2 files changed, 28 insertions, 11 deletions
diff --git a/include/fud_format.hpp b/include/fud_format.hpp index 8dd2231..e80d96e 100644 --- a/include/fud_format.hpp +++ b/include/fud_format.hpp @@ -172,6 +172,8 @@ enum class FormatType : utf8 FixedUpper = 'F', GeneralLower = 'g', GeneralUpper = 'G', + PointerLower = 'p', + PointerUpper = 'P', }; struct FormatSpec; @@ -337,7 +339,6 @@ size_t findSpec(StringView scanView); template <typename Sink, typename... Args> requires Drainable<Sink, StringView> FormatResult format(Sink& sink, FormatCharMode formatMode, FormatString fmt, Args&&... args) { - static_cast<void>(sink); if (formatMode != FormatCharMode::Unchecked) { return {0, FudStatus::NotImplemented}; } @@ -416,6 +417,9 @@ FormatResult vFormat(Sink& sink, FormatCharMode formatMode, FormatString fmt, co result.status = drainResult.status; return result; } + if (specIndex == scanView.length()) { + return result; + } scanView.advanceUnsafe(specIndex); if (specIndex == scanView.length()) { return result; @@ -698,6 +702,8 @@ template <typename T> case FormatType::FixedUpper: case FormatType::GeneralLower: case FormatType::GeneralUpper: + case FormatType::PointerLower: + case FormatType::PointerUpper: result.status = FudStatus::FormatInvalid; break; default: @@ -1270,8 +1276,6 @@ template <typename Sink, typename T> static_assert(std::is_same_v<decltype(decimalRepr.exponent), int32_t>); static_assert(std::is_same_v<decltype(decimalRepr.is_negative), bool>); - static_cast<void>(decimalRepr); - auto uppercaseResult = validateFloatFormatType(formatSpec.formatType); if (uppercaseResult.isError()) { return FormatResult{0, uppercaseResult.takeError()}; @@ -1468,23 +1472,35 @@ FormatResult format(Sink& sink, FormatCharMode formatMode, const FormatSpec& for template <typename Sink> FormatResult format(Sink& sink, FormatCharMode formatMode, const FormatSpec& formatSpec, const void* arg) { - FormatResult result{0, FudStatus::NotImplemented}; - static_cast<void>(sink); - static_cast<void>(formatMode); - static_cast<void>(formatSpec); - static_cast<void>(arg); - return result; + auto pointerFormatSpec = formatSpec; + if (pointerFormatSpec.formatType == FormatType::Unspecified || + pointerFormatSpec.formatType == FormatType::PointerLower) { + pointerFormatSpec.formatType = FormatType::HexLower; + } else if (pointerFormatSpec.formatType == FormatType::PointerUpper) { + pointerFormatSpec.formatType = FormatType::HexUpper; + } else { + return DrainResult{0, FudStatus::FormatInvalid}; + } + pointerFormatSpec.formatType = FormatType::HexLower; + if (pointerFormatSpec.alternateForm || pointerFormatSpec.hasLocale || + pointerFormatSpec.formatSign != FormatSign::Default) { + return DrainResult{0, FudStatus::FormatInvalid}; + } + pointerFormatSpec.alternateForm = true; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) + return impl::formatIntegral(sink, formatMode, pointerFormatSpec, reinterpret_cast<uintptr_t>(arg)); } template <typename Sink> FormatResult format(Sink& sink, FormatCharMode formatMode, const FormatSpec& formatSpec, impl::FormatHandle arg) { - FormatResult result{0, FudStatus::NotImplemented}; + // FormatResult result{0, FudStatus::NotImplemented}; static_cast<void>(sink); static_cast<void>(formatMode); static_cast<void>(formatSpec); static_cast<void>(arg); - return result; + + return format(sink, formatMode, formatSpec, "not implemented"); } } // namespace fud diff --git a/include/fud_status.hpp b/include/fud_status.hpp index f18c119..cd7eac4 100644 --- a/include/fud_status.hpp +++ b/include/fud_status.hpp @@ -22,6 +22,7 @@ namespace fud { +// NOLINTNEXTLINE(performance-enum-size) enum class [[nodiscard]] FudStatus : int32_t { /** \brief Indisputable success. */ |