Fix MSVC warnings in vendored FatFs and xz-embedded#3618
Open
dimension-zero wants to merge 1 commit into
Open
Conversation
ff14/source/ff.c:6169 — sign-extension bug. `~(sz_blk - 1)` produces a 32-bit mask which is then AND'd with a 64-bit LBA_t. MSVC zero-extends the high bits, so the mask is wrong on the high half. Cast the operand to LBA_t before complementing so all high bits are correctly set. xz-embedded/linux/lib/decompress_unxz.c and xz/xz_dec_lzma2.c — explicit narrowing casts at the points where size_t (host pointer arithmetic) is assigned to uint32_t / int (xz protocol fields). These were implicit truncations before; now the intent is documented at the call site. No behavior change on either fix path — the masks and truncations are already what the code intends; this just suppresses the warnings and makes the intent explicit.
5fe046b to
48b7c05
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three small fixes that quiet MSVC build warnings in vendored third-party code shipped with the Windows projects. No behavior change — these are explicit casts/widening that document the existing intent.
Fixes
C4319 sign-extension bug —
Ventoy2Disk/ff14/source/ff.c:6169```c
(LBA_t)(sz_blk - 1)) - b_data);(sz_blk - 1)` produces a 32-bit mask which is then AND'd with a 64-bit `LBA_t`. MSVC zero-extends the high bits, so the mask is wrong on the high half (zeros instead of ones). Casting the operand to `LBA_t` before complementing makes the mask correct.```
`
C4267 narrowing —
Plugson/src/Lib/xz-embedded/linux/lib/decompress_unxz.c3 explicit `(int)` / `(unsigned int)` casts where `size_t` values (`b.in_pos`, `b.out_pos`) are assigned to `int` / `unsigned int` xz protocol fields.
C4267 narrowing —
Plugson/src/Lib/xz-embedded/linux/lib/xz/xz_dec_lzma2.c8 explicit `(uint32_t)` casts at the boundaries between `size_t` arithmetic and `uint32_t` LZMA2 fields.
Notes
Stats
Test plan