-
Couldn't load subscription status.
- Fork 932
Open
Labels
Description
The function lfs_mlist_isopen() only checks if the address exists. So when the address of the lfs_file_t changes the lfs thinks that this file has not been opened, but indeed it has, just the address is different.
Would it be possible to change to a memcmp check instead of a single pointer check in lfs_mlist_isopen() ?
Example code triggering the assert:
lfs_file_t file1;
lfs_file_t file2;
uint8_t buffer[1];
// works fine
lfs_file_open(lfs_fs, &file1, "test1", LFS_O_RDONLY);
lfs_file_read(lfs_fs, &file1, buffer, sizeof(buffer));
memcpy(&file2, &file1, sizeof(file2));
// this call produces an assert (lfs_mlist_isopen)
lfs_file_read(lfs_fs, &file2, buffer, sizeof(buffer));
Inside lfs_mlist_isopen() instead of
if (*p == (struct lfs_mlist*)node) {
return true;
}
we could do
if(memcmp(*p, node, sizeof(*node)) == 0) {
return true;
}
This would make the above code not triggering an assert as I would have expected it.
I am not deep inside the lfs code so this may have some side effects I don't know of. Let me know your thoughts about it.