summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArda Cinar <kuzux92@gmail.com>2022-12-13 15:11:19 +0300
committerTim Flynn <trflynn89@pm.me>2022-12-14 07:45:06 -0500
commit9d9a6b6b64d2d39260233b09c733e525f80a43d8 (patch)
tree9c04376bf40657ea3ce7fc9fbc09be3f80d440fd
parente305b32d9ac235933aeba775ab249812552d9334 (diff)
downloadserenity-9d9a6b6b64d2d39260233b09c733e525f80a43d8.zip
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 :^)
-rw-r--r--Userland/Applications/Presenter/Presentation.cpp8
1 files 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()