From 6705c7929c04226320c697503a941b47217f19dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 24 Sep 2023 12:58:43 +0200 Subject: [PATCH] Some cleanups and fixes to obscure crashes --- Common/Net/HTTPClient.cpp | 4 ++-- Common/Net/HTTPClient.h | 1 - Common/UI/Screen.cpp | 7 +++++-- Core/FileSystems/BlockDevices.cpp | 3 +-- Core/HLE/sceIo.cpp | 6 ++++++ 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Common/Net/HTTPClient.cpp b/Common/Net/HTTPClient.cpp index 3ba3c629442a..c6366af8262d 100644 --- a/Common/Net/HTTPClient.cpp +++ b/Common/Net/HTTPClient.cpp @@ -219,9 +219,9 @@ namespace http { // TODO: do something sane here constexpr const char *DEFAULT_USERAGENT = "PPSSPP"; +constexpr const char *HTTP_VERSION = "1.1"; Client::Client() { - httpVersion_ = "1.1"; userAgent_ = DEFAULT_USERAGENT; } @@ -353,7 +353,7 @@ int Client::SendRequestWithData(const char *method, const RequestParams &req, co "\r\n"; buffer.Printf(tpl, - method, req.resource.c_str(), httpVersion_, + method, req.resource.c_str(), HTTP_VERSION, host_.c_str(), userAgent_.c_str(), req.acceptMime, diff --git a/Common/Net/HTTPClient.h b/Common/Net/HTTPClient.h index dd104e2fa603..619ab80423b6 100644 --- a/Common/Net/HTTPClient.h +++ b/Common/Net/HTTPClient.h @@ -86,7 +86,6 @@ class Client : public net::Connection { protected: std::string userAgent_; - const char *httpVersion_; double dataTimeout_ = 900.0; }; diff --git a/Common/UI/Screen.cpp b/Common/UI/Screen.cpp index 80b8fced14ff..680ceea60b8f 100644 --- a/Common/UI/Screen.cpp +++ b/Common/UI/Screen.cpp @@ -227,9 +227,11 @@ void ScreenManager::getFocusPosition(float &x, float &y, float &z) { } void ScreenManager::sendMessage(const char *msg, const char *value) { - if (!strcmp(msg, "recreateviews")) + if (!msg) { + _dbg_assert_(false, "Empty msg in ScreenManager::sendMessage"); + } else if (!strcmp(msg, "recreateviews")) { RecreateAllViews(); - if (!strcmp(msg, "lost_focus")) { + } else if (!strcmp(msg, "lost_focus")) { TouchInput input{}; input.x = -50000.0f; input.y = -50000.0f; @@ -238,6 +240,7 @@ void ScreenManager::sendMessage(const char *msg, const char *value) { input.id = 0; touch(input); } + if (!stack_.empty()) stack_.back().screen->sendMessage(msg, value); } diff --git a/Core/FileSystems/BlockDevices.cpp b/Core/FileSystems/BlockDevices.cpp index c1c930f0c610..05f3a87d1a4d 100644 --- a/Core/FileSystems/BlockDevices.cpp +++ b/Core/FileSystems/BlockDevices.cpp @@ -393,7 +393,7 @@ NPDRMDemoBlockDevice::NPDRMDemoBlockDevice(FileLoader *fileLoader) fileLoader_->ReadAt(0x24, 1, 4, &psarOffset); size_t readSize = fileLoader_->ReadAt(psarOffset, 1, 256, &np_header); - if(readSize!=256){ + if (readSize != 256){ ERROR_LOG(LOADER, "Invalid NPUMDIMG header!"); } @@ -445,7 +445,6 @@ NPDRMDemoBlockDevice::NPDRMDemoBlockDevice(FileLoader *fileLoader) } currentBlock = -1; - } NPDRMDemoBlockDevice::~NPDRMDemoBlockDevice() diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index b554d34e806b..d8599f98650a 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -1486,6 +1486,12 @@ static u32 sceIoLseek32Async(int id, int offset, int whence) { } static FileNode *__IoOpen(int &error, const char *filename, int flags, int mode) { + if (!filename) { + // To prevent crashes. Not sure about the correct value. + error = SCE_KERNEL_ERROR_ERRNO_FILE_NOT_FOUND; + return nullptr; + } + int access = FILEACCESS_NONE; if (flags & PSP_O_RDONLY) access |= FILEACCESS_READ;