From b476c54825621bc0ebc16a72e9d8c87181a1a7e7 Mon Sep 17 00:00:00 2001 From: ITotalJustice <47043333+ITotalJustice@users.noreply.github.com> Date: Sat, 13 Sep 2025 13:28:55 +0100 Subject: [PATCH] devoptab: add workaround for dkp nullptr bug. manually set the array at startup to avoid nullptr access. --- sphaira/include/utils/devoptab.hpp | 4 ++++ sphaira/source/app.cpp | 2 ++ sphaira/source/utils/devoptab_common.cpp | 16 ++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/sphaira/include/utils/devoptab.hpp b/sphaira/include/utils/devoptab.hpp index 752e65c..480ecd3 100644 --- a/sphaira/include/utils/devoptab.hpp +++ b/sphaira/include/utils/devoptab.hpp @@ -32,4 +32,8 @@ Result GetNetworkDevices(location::StdioEntries& out); void UmountAllNeworkDevices(); void UmountNeworkDevice(const fs::FsPath& mount); +// manually set the array so that we can avoid nullptr access. +// SEE: https://github.com/devkitPro/newlib/issues/35 +void FixDkpBug(); + } // namespace sphaira::devoptab diff --git a/sphaira/source/app.cpp b/sphaira/source/app.cpp index 45f6f11..2b028ef 100644 --- a/sphaira/source/app.cpp +++ b/sphaira/source/app.cpp @@ -1567,6 +1567,8 @@ App::App(const char* argv0) { } } + devoptab::FixDkpBug(); + #ifdef ENABLE_LIBHAZE if (App::GetMtpEnable()) { SCOPED_TIMESTAMP("mtp init"); diff --git a/sphaira/source/utils/devoptab_common.cpp b/sphaira/source/utils/devoptab_common.cpp index 919af73..e894902 100644 --- a/sphaira/source/utils/devoptab_common.cpp +++ b/sphaira/source/utils/devoptab_common.cpp @@ -11,6 +11,11 @@ #include #include +// see FixDkpBug(); +extern "C" { + extern const devoptab_t dotab_stdnull; +} + namespace sphaira::devoptab::common { namespace { @@ -1544,4 +1549,15 @@ void UmountNeworkDevice(const fs::FsPath& mount) { } } +void FixDkpBug() { + const int max = 35; + + for (int i = 0; i < max; i++) { + if (!devoptab_list[i]) { + devoptab_list[i] = &dotab_stdnull; + log_write("[DEVOPTAB] Fixing DKP bug at index: %d\n", i); + } + } +} + } // sphaira::devoptab