Repository navigation
build(linux-v4l2): compile the plugin with the conversion warnings enabled (#2625) - #2849
Conversation
…#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
left a comment
There was a problem hiding this comment.
Reviewed the diff against the ratchet the earlier slices set (#2740 linux-pulseaudio, linux-alsa).
Verified:
- The
target_compile_optionsblock is the same shape and genex guard asplugins/linux-alsa/CMakeLists.txtandplugins/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:
devbecomes a realintfd end to end instead ofint_fast32_t(longon x86-64) narrowed again at everyv4l2_ioctl/v4l2_open/v4l2_close; plane offsets move tosize_t, the V4L2__u32fields keep their casts at the call site,obs_data_get_int'slong longgets an explicit narrowing read. Every cast I checked says what the value already is. - No test or prototype fallout:
test/cmocka/test_v4l2_*.cdo not nameint_fast32_t/uint_fast32_t, andv4l2-controls.h/v4l2-helpers.hare plugin-internal headers (no libobs public API touched). - Build tooling only, so no
docs/features.mdline 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.
Slice for #2625 (conversion ratchet), one target per PR as before:
linux-v4l2.RED
ace3706b6enables-Wconversion -Wsign-conversion -Wfloat-conversionon thelinux-v4l2target only (the shared flag list keeps the global-Wno-*pins until the last target is ratcheted). Build of the target inobs-rust-linux-validatestops with 108 diagnostics:v4l2-input.c.hv4l2-helpers.c.hv4l2-controls.c.hv4l2-framerate.c.hv4l2-decoder.c.hv4l2-output.c.hGREEN
61ce1fac3fixes them at the call sites, mostly by saying what the value already is:devis anintend to end (it wasint_fast32_t—longon x86-64 — narrowed again at everyv4l2_ioctl/v4l2_open/v4l2_close); the buffer count and the pixel format are theuint32_tV4L2 reports;size_tfrom the signedlinesize/heightthe OBS frame carries;v4l2_pack_tupletakes a signed pair, so its call sites cast the__u32fields it packs;obs_data_get_intis along long; the nine settings it fills are ints, so the narrowing reads say so;V4L2_FOURCC_STRwrites 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.solinks../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.mdline.