Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvng <viktor.govako@gmail.com>2013-01-19 15:38:29 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:49:02 +0300
commit62a272930969a5443fa80436dcc05ebef856bef2 (patch)
treea4c4b01342c18d2f597b2322483b1fbe898d5f24 /map/bookmark.cpp
parent52d4124b3c7a4647c5abbe066de0f1832df93c02 (diff)
Fix possible crash in name generation.
Diffstat (limited to 'map/bookmark.cpp')
-rw-r--r--map/bookmark.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/map/bookmark.cpp b/map/bookmark.cpp
index b5feeb3c49..cc6d253e44 100644
--- a/map/bookmark.cpp
+++ b/map/bookmark.cpp
@@ -450,16 +450,23 @@ string BookmarkCategory::RemoveInvalidSymbols(string const & name)
string BookmarkCategory::GenerateUniqueFileName(const string & path, string name)
{
string const kmlExt(".kml");
+
// check if file name already contains .kml extension
size_t const extPos = name.rfind(kmlExt);
- if (extPos == name.size() - kmlExt.size())
- name.resize(name.size() - kmlExt.size());
+ if (extPos != string::npos)
+ {
+ // remove extension
+ ASSERT_GREATER_OR_EQUAL(name.size(), kmlExt.size(), ());
+ size_t const expectedPos = name.size() - kmlExt.size();
+ if (extPos == expectedPos)
+ name.resize(expectedPos);
+ }
size_t counter = 1;
string suffix;
- while (Platform::IsFileExistsByFullPath(path + name + suffix + ".kml"))
+ while (Platform::IsFileExistsByFullPath(path + name + suffix + kmlExt))
suffix = strings::to_string(counter++);
- return (path + name + suffix + ".kml");
+ return (path + name + suffix + kmlExt);
}
bool BookmarkCategory::SaveToKMLFile()