From 702d308e67b369fbbfb863442df23a328b6055a3 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 22 Oct 2018 13:10:08 +0200 Subject: [PATCH] Oops, StringImpl's "the empty string" global was not always initialized. These "oops forgot to initialize" bugs are getting annoying... --- AK/StringImpl.cpp | 13 +++++++++---- AK/StringImpl.h | 1 + Kernel/init.cpp | 7 ++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/AK/StringImpl.cpp b/AK/StringImpl.cpp index 1c00f5a35e4..be83cfc4192 100644 --- a/AK/StringImpl.cpp +++ b/AK/StringImpl.cpp @@ -4,12 +4,17 @@ namespace AK { +static StringImpl* s_theEmptyStringImpl = nullptr; + +void StringImpl::initializeGlobals() +{ + s_theEmptyStringImpl = new StringImpl(ConstructTheEmptyStringImpl);; +} + StringImpl& StringImpl::theEmptyStringImpl() { - static StringImpl* s = nullptr; - if (!s) - s = new StringImpl(ConstructTheEmptyStringImpl); - return *s; + ASSERT(s_theEmptyStringImpl); + return *s_theEmptyStringImpl; } StringImpl::~StringImpl() diff --git a/AK/StringImpl.h b/AK/StringImpl.h index 2278438f6cb..b52a252277b 100644 --- a/AK/StringImpl.h +++ b/AK/StringImpl.h @@ -15,6 +15,7 @@ public: RetainPtr toUppercase() const; static StringImpl& theEmptyStringImpl(); + static void initializeGlobals(); ~StringImpl(); diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 65d784923b3..844a7107f81 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -27,7 +27,7 @@ #include "Console.h" #define TEST_VFS -//#define TEST_ELF_LOADER +#define TEST_ELF_LOADER //#define TEST_CRASHY_USER_PROCESSES static void motd_main() NORETURN; @@ -102,8 +102,6 @@ static void init_stage2() // Anything that registers interrupts goes *after* PIC and IDT for obvious reasons. Syscall::initialize(); - VirtualFileSystem::initializeGlobals(); - extern void panel_main(); new Task(panel_main, "panel", IPC::Handle::PanelTask, Task::Ring0); @@ -203,6 +201,9 @@ void init() MemoryManager::initialize(); + VirtualFileSystem::initializeGlobals(); + StringImpl::initializeGlobals(); + auto keyboard = make(); PIT::initialize();