Skip to content

build(linux-v4l2): compile the plugin with the conversion warnings enabled (#2625) - #2849

Merged
zackees merged 2 commits into
masterfrom
infra/2625-conversion-linux-v4l2
Oct 28, 2026
Merged

zackees merged 2 commits into
masterfrom
infra/2625-conversion-linux-v4l2

Conversation

@zackees

@zackees zackees commented Oct 28, 2026

Copy link
Copy Markdown
Member

Slice for #2625 (conversion ratchet), one target per PR as before: linux-v4l2.

RED

ace3706b6 enables -Wconversion -Wsign-conversion -Wfloat-conversion on the linux-v4l2 target only (the shared flag list keeps the global -Wno-* pins until the last target is ratcheted). Build of the target in obs-rust-linux-validate stops with 108 diagnostics:

file diagnostics
v4l2-input.c.h 55
v4l2-helpers.c.h 32
v4l2-controls.c.h 11
v4l2-framerate.c.h 7
v4l2-decoder.c.h 2
v4l2-output.c.h 1

GREEN

61ce1fac3 fixes them at the call sites, mostly by saying what the value already is:

  • a device handle is a file descriptor, so dev is an int end to end (it was int_fast32_t — long on x86-64 — narrowed again at every v4l2_ioctl/v4l2_open/v4l2_close); the buffer count and the pixel format are the uint32_t V4L2 reports;
  • plane offsets are byte counts, computed as size_t from the signed linesize/height the OBS frame carries;
  • v4l2_pack_tuple takes a signed pair, so its call sites cast the __u32 fields it packs;
  • obs_data_get_int is a long long; the nine settings it fills are ints, so the narrowing reads say so;
  • the select timeout and the two fps computations divide float by float;
  • V4L2_FOURCC_STR writes chars; the fourcc log, the frame-interval enumeration and the virtual-camera write loop cast their one deliberate narrowing each.

Rebuilt in obs-rust-linux-validate (e756cdba69646bd5) with the groups enabled: 108 → 0 diagnostics, linux-v4l2.so links. ./lint: lane lint: ok (54.3 s).

Refs #2625 — the global pin deletion is the last slice, after the remaining first-party targets.

Build tooling only, so no docs/features.md line.

…#2625)

RED: linux-v4l2 compiles with its own -Wconversion, -Wsign-conversion and
-Wfloat-conversion instead of inheriting the global -Wno-* pins. The target
build reports 108 diagnostics in v4l2-input.c.h (55), v4l2-helpers.c.h (32),
v4l2-controls.c.h (11), v4l2-framerate.c.h (7), v4l2-decoder.c.h (2) and
v4l2-output.c.h (1), so the build stops.

Refs #2625
)

The target now compiles with -Wconversion, -Wsign-conversion and
-Wfloat-conversion, so its conversions have to be explicit:

- a device handle is a file descriptor, so `dev` is an `int` end to end
  (it was `int_fast32_t`, widened to `long` and narrowed again at every
  v4l2_ioctl/v4l2_open/v4l2_close call); the buffer count and the pixel
  format are `uint32_t`, the width V4L2 reports;
- plane offsets are a byte count, so they are computed as `size_t` from
  the signed `linesize`/`height` the OBS frame already carries;
- frame sizes and rates come back from v4l2_pack_tuple as a signed pair,
  so its call sites cast the `__u32` fields it packs;
- obs_data_get_int is a long long; the settings it fills are ints, so the
  nine narrowing reads say so;
- the two float computations (select timeout, fps for the log and the
  list) divide float by float instead of int by int;
- the V4L2_FOURCC_STR bytes are chars, written explicitly;
- the fourcc log, the frame interval enumeration and the virtual-camera
  write loop cast their one deliberate narrowing each.

Rebuilt in obs-rust-linux-validate with the groups enabled: 108 -> 0
diagnostics, linux-v4l2.so links. `./lint` ok (54 s).

Refs #2625

@zackees zackees left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the diff against the ratchet the earlier slices set (#2740 linux-pulseaudio, linux-alsa).

Verified:

  • The target_compile_options block is the same shape and genex guard as plugins/linux-alsa/CMakeLists.txt and plugins/linux-pulseaudio/CMakeLists.txt, so the target-only opt-in and the "global pins stay until the last target" comment match the ratchet's stated shape.
  • The narrowing is honest rather than silenced: dev becomes a real int fd end to end instead of int_fast32_t (long on x86-64) narrowed again at every v4l2_ioctl/v4l2_open/v4l2_close; plane offsets move to size_t, the V4L2 __u32 fields keep their casts at the call site, obs_data_get_int's long long gets an explicit narrowing read. Every cast I checked says what the value already is.
  • No test or prototype fallout: test/cmocka/test_v4l2_*.c do not name int_fast32_t/uint_fast32_t, and v4l2-controls.h/v4l2-helpers.h are plugin-internal headers (no libobs public API touched).
  • Build tooling only, so no docs/features.md line is right.

One finding, non-blocking (debug-only code, so CI will not see it):

v4l2_query_all_buffers is #ifdef _DEBUG, and its three log lines still format with PRIuFAST32 after count and i became plain uint:

plugins/linux-v4l2/v4l2-helpers.c.h:76  ... %" PRIuFAST32 " buffers", buf_data->count
:83  ... buffer #%" PRIuFAST32, i
:86  "query buf #%" PRIuFAST32 ...

On glibc x86-64 PRIuFAST32 expands to "lu" (that is uint_fast32_t = unsigned long), so -Wformat now reports "format '%lu' expects 'long unsigned int', but argument has type 'uint' {aka 'unsigned int'}" — I reproduced it locally with those exact two lines — and the vararg read is 8 bytes wide for a 4-byte argument. cmake/linux/compilerconfig.cmake enables -Wformat/-Wformat=2 and defines _DEBUG for $<CONFIG:DEBUG> (:108), so this is the one warning left in the file this PR is meant to leave at zero, in Debug builds. "%u" (or (unsigned long) at the argument) is the fix. It does not block landing, so I am not pushing it over your head while PR CI is mid-flight; say the word and I will add it as a fixup.

Status at review time: Fast Gate and Rust Tier 2 Linux (build) still running; I will queue the PR when checks are green and the state is CLEAN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant