From 5611c6a0a0c2bcf7c3d79e39bd28c0c5873061b0 Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Sun, 3 Aug 2014 13:28:05 -0700 Subject: [PATCH] chore(util/lean_path): workaround 'spurious' warning produced by g++ in release mode Signed-off-by: Leonardo de Moura --- src/util/lean_path.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/util/lean_path.cpp b/src/util/lean_path.cpp index f202555cd..9a59fcdb2 100644 --- a/src/util/lean_path.cpp +++ b/src/util/lean_path.cpp @@ -294,21 +294,26 @@ void display_path(std::ostream & out, std::string const & fname) { std::string dirname(char const * fname) { if (fname == nullptr) return "."; - unsigned i = 0; - optional last_sep; - char const * it = fname; + unsigned i = 0; + unsigned last_sep = 0; + bool found_sep = false; + char const * it = fname; while (*it) { - if (*it == g_sep) - last_sep = i; + if (*it == g_sep) { + found_sep = true; + last_sep = i; + } ++i; ++it; } - if (!last_sep) + if (!found_sep) { return "."; - std::string r; - for (unsigned i = 0; i < *last_sep; i++) - r.push_back(fname[i]); - return r; + } else { + std::string r; + for (unsigned i = 0; i < last_sep; i++) + r.push_back(fname[i]); + return r; + } } std::string path_append(char const * p1, char const * p2) {