Fix CTZ traverse pointer conversion count - #1217
Conversation
Convert only the CTZ head pointers that were read successfully. This avoids reading an uninitialized heads[1] slot when the CTZ index only requires one pointer. Generated-by: OpenAI Codex Signed-off-by: aineoae86-sys <ai.neo.ae86@gmail.com>
Tests passed ✓, Code: 17200 B (+0.0%), Stack: 1448 B (+0.0%), Structs: 812 B (+0.0%)
|
Kishore-Gorijavolu
left a comment
There was a problem hiding this comment.
Reviewed the CTZ traversal change and independently tested it against both the pre-fix and PR revisions.
The change looks correct to me. In the existing implementation, count can be either 1 or 2, but both heads[0] and heads[1] were unconditionally passed through lfs_fromle32(). When count == 1, only one entry is populated by lfs_bd_read(), so converting heads[1] unnecessarily accesses an uninitialized element.
This patch addresses that cleanly by:
- checking the
lfs_bd_read()result before consuming the returned data; - converting only
countentries using the bounded loop; and - preserving the subsequent
heads[count-1]traversal behavior.
I also performed a focused before/after test using the same test source against both revisions. The test created a 4096-byte multi-block file and exercised lfs_fs_traverse(). Both revisions completed successfully with the same 19-block traversal sequence, indicating no functional regression in the exercised CTZ traversal path.
I attempted to run the complete test suite locally as an additional regression check, but the local Windows/MSYS Python environment could not execute the littlefs test infrastructure because the POSIX termios module was unavailable. I therefore did not treat that attempt as a project test result. The PR's GitHub CI checks are passing.
The implementation is appropriately scoped to the pointer-conversion and read-error handling path.
Approved.
Summary
lfs_bd_readactually filledheads[1]slot whencount == 1Fixes #1214
Testing
git diff --checkgit ls-files --eol lfs.cmake testrequires the project test toolchain, but this Windows host does not havemake,cc, orgccavailable.