From 762ddb096d103d2e8947c453dc0a1375764e83f2 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Mon, 24 Aug 2015 19:35:44 -0700 Subject: [PATCH] GUI: Handle paths starting with / properly --- src/util/gui/file-select.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/util/gui/file-select.c b/src/util/gui/file-select.c index e88eee5a7..8e40372e0 100644 --- a/src/util/gui/file-select.c +++ b/src/util/gui/file-select.c @@ -26,6 +26,10 @@ static void _upDirectory(char* currentPath) { if (!end) { return; } + if (end == currentPath) { + end[1] = '\0'; + return; + } end[0] = '\0'; if (end[1]) { return; @@ -85,7 +89,12 @@ bool selectFile(const struct GUIParams* params, const char* basePath, char* outP return false; } if (newInput & (1 << GUI_INPUT_SELECT)) { - snprintf(currentPath, sizeof(currentPath), "%s%c%s", currentPath, '/', *FileListGetPointer(¤tFiles, fileIndex)); + size_t len = strlen(currentPath); + const char* sep = PATH_SEP; + if (currentPath[len - 1] == *sep) { + sep = ""; + } + snprintf(currentPath, sizeof(currentPath), "%s%s%s", currentPath, sep, *FileListGetPointer(¤tFiles, fileIndex)); if (!_refreshDirectory(currentPath, ¤tFiles)) { strncpy(outPath, currentPath, outLen); return true;