Skip to content

Runtime assertion in lfs_format due to uninitialized variable use (VS 2022) #756

Open
@knaxr

Description

@knaxr

MSVC debug build will emit a runtime assertion related to the use of uninitialized variable in
lfs_dir_traverse:
"Run-Time Check Failure #3 - The variable 'disk' is being used without being initialized."
This occurs when calling lfs_format on a completely erased (0xff bytes) ram block device.
callstack:

lfs_dir_traverse() Line 850 (littlefs-2.5.1\lfs.c:850)
lfs_dir_compact() Line 1799 (littlefs-2.5.1\lfs.c:1799)
lfs_dir_splittingcompact() Line 2000 (littlefs-2.5.1\lfs.c:2000)
lfs_dir_relocatingcommit() Line 2117 (littlefs-2.5.1\lfs.c:2117)
lfs_dir_orphaningcommit() Line 2198 (littlefs-2.5.1\lfs.c:2198)
lfs_dir_commit() Line 2370 (littlefs-2.5.1\lfs.c:2370)
lfs_rawformat() Line 4066 (littlefs-2.5.1\lfs.c:4066)
lfs_format() Line 5324 (littlefs-2.5.1\lfs.c:5324)

We removed the displayed assertion message box by initializing struct lfs_diskoff disk with 0 in lfs.c line 811:
struct lfs_diskoff disk = {0};

Can someone confirm, that zero-initializing disk is safe or if this may lead to unexpected side effects?
If required, I'm happy to provide more information.

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