Skip to content

lfs_mlist_isopen causing assert on already open file if address changes #765

@DevLev100

Description

@DevLev100

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions