From 9d9a6b6b64d2d39260233b09c733e525f80a43d8 Mon Sep 17 00:00:00 2001 From: Arda Cinar Date: Tue, 13 Dec 2022 15:11:19 +0300 Subject: Presenter: Fix a crash in loading untitled presentations The Presentation::title() and Presentation::author() functions return a StringView to the title/author defined in the json file or a default value. Previously, this would return a StringView to already-freed memory and crash the application when setting the window title. This commit fixes that issue :^) --- Userland/Applications/Presenter/Presentation.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Userland/Applications/Presenter/Presentation.cpp b/Userland/Applications/Presenter/Presentation.cpp index 27fc6a529a..bb12f74945 100644 --- a/Userland/Applications/Presenter/Presentation.cpp +++ b/Userland/Applications/Presenter/Presentation.cpp @@ -30,12 +30,16 @@ void Presentation::append_slide(Slide slide) StringView Presentation::title() const { - return m_metadata.get("title"sv).value_or("Untitled Presentation"sv); + if (m_metadata.contains("title"sv)) + return m_metadata.get("title"sv)->view(); + return "Untitled Presentation"sv; } StringView Presentation::author() const { - return m_metadata.get("author"sv).value_or("Unknown Author"sv); + if (m_metadata.contains("author"sv)) + return m_metadata.get("author"sv)->view(); + return "Unknown Author"sv; } void Presentation::next_frame() -- cgit v1.2.3