summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuriy Petrochenkov <jupetr@gmail.com>2019-08-17 12:11:01 +0300
committerCharles Pigott <charlespigott@googlemail.com>2019-10-25 22:35:51 +0100
commit8c6a16ba287231e14ec700926c93c8d32449cef2 (patch)
tree2e3a88b0ae5a84027444436c4ee08a1dba193790
parentf13b18458887dfe0275148423d80ce9defa9e5b1 (diff)
downloadopenttd-8c6a16ba287231e14ec700926c93c8d32449cef2.tar.xz
Fix: Possible double path separator in FiosMakeFilename
-rw-r--r--src/fios.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/fios.cpp b/src/fios.cpp
index 4e614e498..c717c1f4f 100644
--- a/src/fios.cpp
+++ b/src/fios.cpp
@@ -205,12 +205,18 @@ const char *FiosBrowseTo(const FiosItem *item)
*/
static void FiosMakeFilename(char *buf, const char *path, const char *name, const char *ext, const char *last)
{
- const char *period;
+ if (path != nullptr) {
+ const char *buf_start = buf;
+ buf = strecpy(buf, path, last);
+ /* Remove trailing path separator, if present */
+ if (buf > buf_start && buf[-1] == PATHSEPCHAR) buf--;
+ }
/* Don't append the extension if it is already there */
- period = strrchr(name, '.');
+ const char *period = strrchr(name, '.');
if (period != nullptr && strcasecmp(period, ext) == 0) ext = "";
- seprintf(buf, last, "%s" PATHSEP "%s%s", path, name, ext);
+
+ seprintf(buf, last, PATHSEP "%s%s", name, ext);
}
/**