summaryrefslogtreecommitdiff
path: root/src/common/file_util.cpp
diff options
context:
space:
mode:
authorGravatar Lioncash2019-05-23 14:24:11 -0400
committerGravatar Lioncash2019-05-23 14:24:13 -0400
commit11e9bee91d645cba69e936916394a0a03875c878 (patch)
treef27f82a7cfedb748013fa0d6f236f8dd3583d7e2 /src/common/file_util.cpp
parentcommon/file_util: Remove duplicated documentation comments (diff)
downloadyuzu-11e9bee91d645cba69e936916394a0a03875c878.tar.gz
yuzu-11e9bee91d645cba69e936916394a0a03875c878.tar.xz
yuzu-11e9bee91d645cba69e936916394a0a03875c878.zip
common/file_util: Make GetCurrentDir() return a std::optional
nullptr was being returned in the error case, which, at a glance may seem perfectly OK... until you realize that std::string has the invariant that it may not be constructed from a null pointer. This means that if this error case was ever hit, then the application would most likely crash from a thrown exception in std::string's constructor. Instead, we can change the function to return an optional value, indicating if a failure occurred.
Diffstat (limited to '')
-rw-r--r--src/common/file_util.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index 740310807..d8812837e 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -525,7 +525,7 @@ void CopyDir(const std::string& source_path, const std::string& dest_path) {
525#endif 525#endif
526} 526}
527 527
528std::string GetCurrentDir() { 528std::optional<std::string> GetCurrentDir() {
529// Get the current working directory (getcwd uses malloc) 529// Get the current working directory (getcwd uses malloc)
530#ifdef _WIN32 530#ifdef _WIN32
531 wchar_t* dir; 531 wchar_t* dir;
@@ -535,7 +535,7 @@ std::string GetCurrentDir() {
535 if (!(dir = getcwd(nullptr, 0))) { 535 if (!(dir = getcwd(nullptr, 0))) {
536#endif 536#endif
537 LOG_ERROR(Common_Filesystem, "GetCurrentDirectory failed: {}", GetLastErrorMsg()); 537 LOG_ERROR(Common_Filesystem, "GetCurrentDirectory failed: {}", GetLastErrorMsg());
538 return nullptr; 538 return {};
539 } 539 }
540#ifdef _WIN32 540#ifdef _WIN32
541 std::string strDir = Common::UTF16ToUTF8(dir); 541 std::string strDir = Common::UTF16ToUTF8(dir);