From 72b0a07ffed221769112edc78d4bfa1e3a6e6894 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 21 Feb 2018 14:43:53 -0600 Subject: [PATCH] retarget: Fix path behaviour without leading slash Current behaviour ends up undefined when the constructor leaves early. Now FilePath just discards leading slashes and otherwise asserts if the path is bad. --- platform/FilePath.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/platform/FilePath.cpp b/platform/FilePath.cpp index 0260986989..ee348993f5 100644 --- a/platform/FilePath.cpp +++ b/platform/FilePath.cpp @@ -18,9 +18,10 @@ namespace mbed { FilePath::FilePath(const char* file_path) : file_name(NULL), fb(NULL) { - if ((file_path[0] != '/') || (file_path[1] == 0)) return; + // skip slashes + file_path += strspn(file_path, "/"); - const char* file_system = &file_path[1]; + const char* file_system = file_path; file_name = file_system; int len = 0; while (true) { @@ -36,6 +37,7 @@ FilePath::FilePath(const char* file_path) : file_name(NULL), fb(NULL) { file_name++; } + MBED_ASSERT(len != 0); fb = FileBase::lookup(file_system, len); }