-
Notifications
You must be signed in to change notification settings - Fork 403
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
Bug in truncate function #48
Comments
I think, we can stay unsigned if (cur_size >= new_size + SPIFFS_DATA_PAGE_SIZE(fs)) Not tested!!!! |
Hmm yes, you're right. My bad, an attempt to get rid of warnings, a bit to
|
Well, that was a bit trickier than I thought. Some tests fail after modification - I need to dig a bit deeper in this. Again, thanks for finding this! |
As I said. I think that my fix works pretty good. Am I mistaken?
|
After I applied the fix (any of them) the regression tests fail - it seems something messes up the LUTs. Which is weird, because the fix should be ok. That's why I have to investigate further. |
Update: it seems the fix works when truncating but messes up when fully removing files. Digging on. |
Unsigned overflow bug, and actually missing tests when truncating to other than zero.
Ok, fixed. Needed some more massaging than just casting, more idiocies from my side. |
Oh and thanks yet again ;) |
It's been a pleasure |
Hello,
I was trying to truncate a file using the function spiffs_object_truncate() and I noticed it was not working properly with smaller files. (I tried to truncate a 51 bytes file to 5, for example).
So I noticed this line inside its implementation:
if (cur_size - SPIFFS_DATA_PAGE_SIZE(fs) >= new_size)
In this case, both cur_size and new_size are u32_t. For this reason, even though the left argument in the comparison should be negative, it is not, it is a a very big unsigned int and therefore this condition becomes true when it should be false.
So I changed this line to the following and the issue seemed to be fixed.
if ((s32_t)cur_size - (s32_t)(SPIFFS_DATA_PAGE_SIZE(fs)) >= (s32_t)new_size)
Please confirm that this spotted issue is correct!
Thanks
The text was updated successfully, but these errors were encountered: