Skip to content

fix compiler warning #6018

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 12, 2018
Merged

Conversation

bmcdonnell-ionx
Copy link
Contributor

Resolves the compiler warnings first mentioned here:

../mbed-os/features/filesystem/fat/FATFileSystem.cpp: In member function 'virtual void FATFileSystem::dir_seek(mbed::fs_dir_t, off_t)':
../mbed-os/features/filesystem/fat/FATFileSystem.cpp:661:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (offset < dh->dptr) {
         ~~~~~~~^~~~~~~~~~
../mbed-os/features/filesystem/fat/FATFileSystem.cpp:664:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while (dh->dptr < offset) {
            ~~~~~~~~~^~~~~~~~

I don't actually understand how dir_seek() is doing its job, though. Can someone explain?

@mbed-ci
Copy link

mbed-ci commented Feb 5, 2018

User not whitelisted, CI not run.

@cmonr cmonr requested a review from geky February 6, 2018 01:54
@0xc0170
Copy link
Contributor

0xc0170 commented Feb 7, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Feb 7, 2018

Build : SUCCESS

Build number : 1084
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/6018/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build

@mbed-ci
Copy link

mbed-ci commented Feb 7, 2018

@mbed-ci
Copy link

mbed-ci commented Feb 7, 2018

@geky
Copy link
Contributor

geky commented Feb 7, 2018

Thanks for the pr!

The conditions in dir_seek are handling two different cases:

  1. offset > dptr:

              dptr
              v
    blah blah blah blah blah
                   ^
                   off
    

    Here we can just iterate forward until dptr == off (the while loop).

  2. offset < dptr:

              dptr
              v
    blah blah blah blah blah
         ^
         off
    

    But here we would need to iterate backwards. In theory we could iterate backwards, but it gets complicated because of LFNs. Since ChanFS targets embedded systems and we care more about code footprint than speed (especially in the weird corner case of iterating backwards in a directory), we just rewind completely (the rewind call) and then iterate forwards until dptr == off (the while loop).

It's an interesting case of reusing as much code as possible to keep the code footprint small.

Does that help clarify things?

@bmcdonnell-ionx
Copy link
Contributor Author

Does that help clarify things?

Yes, thanks!

I think my confusion stemmed from figuring that offset would be relative to the current position, not an "absolute" position within the directory.

...This PR should stay open until someone merges it, right? (Just checking, since I have the option to close it.)

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 8, 2018

...This PR should stay open until someone merges it, right? (Just checking, since I have the option to close it.)

@geky Approved?

@geky
Copy link
Contributor

geky commented Feb 8, 2018

Ah my bad, I forgot to click the approve button.

Only open prs are candidates for being merged. Closing a pr is the same as saying you don't want the pr merged.

Although it's easy to reopen closed prs and issues.


Thinking about it, offset is kinda a funny name, but the name comes from the fact that it's an offset from the start of the file/directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants