Skip to content

retarget: Fix path behaviour without leading slash #6156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions platform/FilePath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, "/");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an amusing way to catch a slew of slashes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's more amusing is the rest of the function could be replaced by:

len = strcspn(file_path, "/");


const char* file_system = &file_path[1];
const char* file_system = file_path;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why is this a const char* instead of char*?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because file_path is a const char*. To change to char * would break constness. But this is describing the data, not the pointer itself. If you wanted a const pointer it'd look like this const char *const file_path, and then you would be prevented from modifying the pointer itself. Isn't it beautiful?

file_name = file_system;
int len = 0;
while (true) {
Expand All @@ -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);
}

Expand Down