-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Update FileIO.cpp - Optimization of doBuffer() to avoid shifting the entire buffer #1766
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
Conversation
The fix seems good, nice catch! |
@cmaglie, your suggestion looks good to me. the "if (buffered>0)" doesn't really add anything (in the old code, the loop would already exexcute 0 times when buffered was 0, and readPos is never actually used when buffered is 0. However, looking more closely, it actually seems this code is missing a bit of error handling. Bridge::transfer can return TRANSFER_TIMEOUT (0xFFFF), which is not handled here. In addition, the exceptional case that transfer returns 0 should also be handled (I don't think this should occur in practice, but better handle it anway). However, the current "buffered >0" if does not handle either of the exception cases I described above, so it can just be removed. |
I can update the error handling, but I'm not sure what (if anything) to do in the case where transfer returns 0 bytes.
|
The most important thing to do is to not crash / do out-of-bounds reads, really. Note that in the code, "buffered" is set to the number of bytes How about this (which delays the -1 for buffered until it actually
One more note: your commit message isn't very useful. "Update FileIO.cpp" doesn't really say anything about what is changed, nor does it indicate the change is in the bridge library. The second line explains all this, but the first line should contain a useful summary already. Better would be something like:
|
I made the changes suggested by Matthijs under a new commit. Should Thanks Bob |
Just squash them in the same commit and do a force push, that will update this pullrequest. |
The pull request has been updated. Please let me know if you have any Bob |
I found a problem and need to do one more change - please hold off on the merge until I can update it again. Thanks Bob |
Update FileIO::doBuffer() to check for TRANSFER_TIMEOUT and set buffered to 0, and optimize by incrementing readPos instead of moving all of the data one byte to the left in the buffer to skip the error code byte.
@bobh66 |
I wanted to do some more testing just to be safe but my Yun is having "AVR device not responding" problems. If you are happy with the changes and/or have tested them, that's good enough for me. Hopefully I can recover this board. |
I tested these changes and they work fine. |
Optimization of doBuffer() - instead of moving all of the data one byte to the left in the buffer, increment readPos to skip over the error code byte.