Skip to content

lfs_fs_preporphans makes invalid assumtions on bool type #1132

@elupus

Description

@elupus

In the function lfs_fs_preporphans, the value of lfs_gstate_hasorphans is left shifted 31 steps to set the high bit of the tag.

littlefs/lfs.c

Line 4895 in 8e251dd

((uint32_t)lfs_gstate_hasorphans(&lfs->gstate) << 31));

While lfs_gstate_hasorphans is defined as bool, it's value is actually same as lfs_tag_size, in other word 0 or any nonzero value.

littlefs/lfs.c

Line 420 in 8e251dd

return lfs_tag_size(a->tag);

This causes the high bit, to not be set at all. I've not investigated what issues this might cause. It was found while analyzing a weird clang-tidy warning:

"The result of the left shift is undefined due to shifting '0' by '31', which is unrepresentable in the unsigned version of the return type 'uint32_t'" on the left shift.

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