From 11e9bee91d645cba69e936916394a0a03875c878 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 23 May 2019 14:24:11 -0400 Subject: 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. --- src/common/file_util.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/common/file_util.h') diff --git a/src/common/file_util.h b/src/common/file_util.h index c325f5b49..cde7ddf2d 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -118,7 +119,7 @@ u64 ScanDirectoryTree(const std::string& directory, FSTEntry& parent_entry, bool DeleteDirRecursively(const std::string& directory, unsigned int recursion = 256); // Returns the current directory -std::string GetCurrentDir(); +std::optional GetCurrentDir(); // Create directory and copy contents (does not overwrite existing files) void CopyDir(const std::string& source_path, const std::string& dest_path); -- cgit v1.2.3