From dc8dd21a4786a7e1e25c8a58fd2a6a3e330b6a6d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Tue, 14 Aug 2018 17:59:09 +0200
Subject: [PATCH] Do not try to access position -1 in string
This ain't python ;(
---
utility/strutil.cpp | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/utility/strutil.cpp b/utility/strutil.cpp
index 643e3baf99..da2819d13f 100644
--- a/utility/strutil.cpp
+++ b/utility/strutil.cpp
@@ -72,20 +72,16 @@ std::string fix(const std::string userPath, const string& delimiters)
string trimmedPath = trim(userPath, delimiters);
string fixedPath;
+ char prev = 0;
// In this loop, we check if there are more than one '/' together. If yes,
// then accept only first one and reject other.
for(unsigned int i = 0; i < trimmedPath.size(); ++i)
{
const char c = trimmedPath[i];
- if('/' == c)
- {
- if('/' != fixedPath[fixedPath.size()-1])
- fixedPath.push_back(c);
- }
- else
+ if(c != '/' || c != prev)
fixedPath.push_back(c);
-
+ prev = c;
}
return fixedPath;
}