From 0f8a6e574cdf638f81c73e782937a55d16225fe3 Mon Sep 17 00:00:00 2001 From: Max Wipfli Date: Tue, 6 Jul 2021 12:55:08 +0200 Subject: [PATCH] Kernel: Add formatter function for OwnPtr This adds a formatter function for OwnPtr. This is added mainly because lots of dbgln() statements generate Strings (such as absolute paths) which are only used for debugging. Instead of catching possible OOM situations at all the dbgln() callsites, this makes it possible to let the formatter code handle those situations by outputting "[out of memory]" if the OwnPtr is null. --- Kernel/KString.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Kernel/KString.h b/Kernel/KString.h index cb7a79b06a..cb0ce3b854 100644 --- a/Kernel/KString.h +++ b/Kernel/KString.h @@ -48,7 +48,18 @@ template<> struct Formatter : Formatter { void format(FormatBuilder& builder, Kernel::KString const& value) { - Formatter::format(builder, value.characters()); + Formatter::format(builder, value.view()); + } +}; + +template<> +struct Formatter> : Formatter { + void format(FormatBuilder& builder, OwnPtr const& value) + { + if (value) + Formatter::format(builder, value->view()); + else + Formatter::format(builder, "[out of memory]"sv); } };