chore(util/lean_path): workaround 'spurious' warning produced by g++ in release mode

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-08-03 13:28:05 -07:00
parent 50b0c17092
commit 5611c6a0a0

View file

@ -294,21 +294,26 @@ void display_path(std::ostream & out, std::string const & fname) {
std::string dirname(char const * fname) { std::string dirname(char const * fname) {
if (fname == nullptr) if (fname == nullptr)
return "."; return ".";
unsigned i = 0; unsigned i = 0;
optional<unsigned> last_sep; unsigned last_sep = 0;
char const * it = fname; bool found_sep = false;
char const * it = fname;
while (*it) { while (*it) {
if (*it == g_sep) if (*it == g_sep) {
last_sep = i; found_sep = true;
last_sep = i;
}
++i; ++i;
++it; ++it;
} }
if (!last_sep) if (!found_sep) {
return "."; return ".";
std::string r; } else {
for (unsigned i = 0; i < *last_sep; i++) std::string r;
r.push_back(fname[i]); for (unsigned i = 0; i < last_sep; i++)
return r; r.push_back(fname[i]);
return r;
}
} }
std::string path_append(char const * p1, char const * p2) { std::string path_append(char const * p1, char const * p2) {