From 0b400af9519444deef4cc6ad2c43c30e2092ab4f Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Sat, 4 Jan 2025 09:56:12 -0600 Subject: Fix bug related to string copying. --- source/libfud.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'source/libfud.cpp') diff --git a/source/libfud.cpp b/source/libfud.cpp index be43490..c4e4b5b 100644 --- a/source/libfud.cpp +++ b/source/libfud.cpp @@ -35,20 +35,23 @@ FUD fud() return fudInfo; } -Result getEnv(const char* name, Allocator* allocator) +Result, FudStatus> getEnv(const char* name, Allocator* allocator) { - using RetType = Result; - if (name == nullptr) { - return RetType::error(FudStatus::NullPointer); + return Error{FudStatus::NullPointer}; } const char* resultString = getenv(name); if (resultString == nullptr) { - return RetType::error(FudStatus::NotFound); + return Okay{Option{NullOpt}}; + } + + auto result{String::makeFromCString(resultString, allocator)}; + if (result.isError()) { + return Error{result.takeError()}; } - return String::makeFromCString(resultString, allocator); + return Okay{Option::take(result.takeOkay())}; } } // namespace fud -- cgit v1.2.3