From d3fcf00d553081610e53112392440d3ff750d3e0 Mon Sep 17 00:00:00 2001 From: gmcode Date: Mon, 28 Aug 2017 12:19:03 +1200 Subject: [PATCH] Small exception safety improvement. --- tz.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tz.cpp b/tz.cpp index f5f3cf9..c6f7e6b 100644 --- a/tz.cpp +++ b/tz.cpp @@ -211,10 +211,11 @@ expand_path(std::string path) return date::iOSUtils::get_tzdata_path(); # else // !TARGET_OS_IPHONE ::wordexp_t w{}; + std::unique_ptr<::wordexp_t, void(*)(::wordexp_t*)> hold{&w, ::wordfree}; ::wordexp(path.c_str(), &w, 0); - assert(w.we_wordc == 1); + if (w.we_wordc != 1) + throw std::runtime_error("Cannot expand path: " + path); path = w.we_wordv[0]; - ::wordfree(&w); return path; # endif // !TARGET_OS_IPHONE }