Skip to content

Fix MSVC warnings in vendored FatFs and xz-embedded#3618

Open
dimension-zero wants to merge 1 commit into
ventoy:masterfrom
dimension-zero:vendored-warnings-msvc
Open

Fix MSVC warnings in vendored FatFs and xz-embedded#3618
dimension-zero wants to merge 1 commit into
ventoy:masterfrom
dimension-zero:vendored-warnings-msvc

Conversation

@dimension-zero

Copy link
Copy Markdown

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

  • n = (DWORD)(((b_data + sz_blk - 1) & ~(sz_blk - 1)) - b_data);
  • n = (DWORD)(((b_data + sz_blk - 1) & (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.c
3 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.c
8 explicit `(uint32_t)` casts at the boundaries between `size_t` arithmetic and `uint32_t` LZMA2 fields.

Notes

  • All three files are vendored. The FatFs change is against ff14 source in this tree; if upstream prefers to forward this to the FatFs project, happy to do so.
  • The xz-embedded changes mirror the spirit of similar narrowing-cast cleanups in the Linux kernel's tree, but applied locally to keep MSVC happy without touching the kernel's copy.

Stats

  • 3 files changed: +12 / −12

Test plan

  • `Ventoy2Disk.vcxproj` builds Win32 + x64 Release without C4319 or C4267 warnings
  • `VentoyPlugson.vcxproj` builds Win32 + x64 Release without C4267 warnings
  • Output binaries are byte-equivalent in behavior (no runtime change — these are no-op casts wrt actual values stored)

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.
@dimension-zero dimension-zero force-pushed the vendored-warnings-msvc branch from 5fe046b to 48b7c05 Compare May 20, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant