Skip to content

build(c-oracle): Add -Wformat=2 and -Wconversion to STRICT_FLAGS - #2632

Merged
zackees merged 3 commits into
masterfrom
infra/2622-c-oracle-format2-conversion
Oct 27, 2026
Merged

zackees merged 3 commits into
masterfrom
infra/2622-c-oracle-format2-conversion

Conversation

@zackees

@zackees zackees commented Oct 27, 2026

Copy link
Copy Markdown
Member

Adds the last two Phase 1 flags of #516 to the C oracle's STRICT_FLAGS and makes every target clean under them.

Fixes #2622.

RED — b522192da

rust/obs-c-oracle/build.rs: STRICT_FLAGS gains -Wformat=2 and -Wconversion (the MSVC branch is untouched). soldr cargo build -p obs-c-oracle fails on the first site:

libobs/util/serializer.h:91:21: error: conversion from 'int' to 'uint8_t' {aka 'unsigned char'} may change value [-Werror=conversion]
   91 |         s_w8(s, u16 >> 8);
      |                 ~~~~^~~~
cc1: all warnings being treated as errors

GREEN — 1bb55c4f7

37 findings at 30 sites over 9 first-party libobs/ files, each fixed with an explicit cast — exactly the conversion the compiler already performed implicitly, so no value changes:

file sites
libobs/util/serializer.h 2 ((uint8_t)(u16 >> 8))
libobs/util/source-profiler.c.h 4 ((uint8_t)((idx + 1) % FRAME_BUFFER_SIZE))
libobs/util/profiler-io.c.h 16 ((double)…)
libobs/util/profiler.c.h 1 ((double)map->occupied / (double)map->size)
libobs/util/platform-nix.c.h 3 ((int)sysconf(...), (useconds_t)remain_us)
libobs/obs-audio-controls.c.h 1 (sum / (float)nr_samples)
libobs/obs-output-interleave.c.h 1 ((double)(out.pts * out.timebase_num))
libobs/media-io/media-remux.c.h 1 ((float)pkt.pos / (float)job->in_size * 100.f)
libobs/audio-monitoring/pulse/pulseaudio-monitor-format.c.h 1 ((float)*cur * vol)

No -Wno-* flag and no #pragma was added; no exemption for a first-party file. Both flags stay in STRICT_FLAGS.

Verification

  • soldr cargo build -p obs-c-oracle — clean (Finished dev profile), all TUs compiled.
  • soldr cargo test -p obs-c-oracle --no-run — clean.
  • clang-format --dry-run --Werror on the nine changed files — clean.

Host Linux is verified here; PR CI's cross lane (ci/local_gate.py) compiles every oracle TU for x86_64-pc-windows-gnu, x86_64-pc-windows-msvc and both Apple targets.

No docs/features.md line: build tooling only.

RED: STRICT_FLAGS gains the two Phase 1 flags of #516, and the oracle
build fails on the first violation:

  libobs/util/serializer.h:91:21: error: conversion from 'int' to
  'uint8_t' {aka 'unsigned char'} may change value [-Werror=conversion]
     91 |         s_w8(s, u16 >> 8);

Refs #2622, #516.
GREEN for the two STRICT_FLAGS added in the RED commit: explicit casts
where the oracle's C converts int/size_t/uint64_t to uint8_t/float/double.
No -Wno-* flag and no pragma; values unchanged.

Refs #2622, #516.
@zackees

zackees commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

Handed off to the coordinator. Both flags are in STRICT_FLAGS, the host build and the oracle test binary compile clean, and clang-format passes; PR CI (the cross lane) is the gate. Auto-merge is on.

@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.

Coordinator review (author account, so this is a review comment rather than an approval).

Verdict: the flag change and the 30 casts are right; nothing to change. I read every hunk in the diff, not only the summary table:

  • rust/obs-c-oracle/build.rs — -Wformat=2 and -Wconversion join STRICT_FLAGS; the MSVC branch is untouched, and no -Wno-* or #pragma is introduced anywhere in the diff. -Wformat=2 is -Wformat -Wformat-security -Wformat-nonliteral, so next to the existing -Wformat-nonliteral the net new coverage is -Wformat-security; that is the intent of #516's Phase 1 list.
  • libobs/util/serializer.h — (uint8_t)(u16 >> 8) is the exact narrowing s_w8's parameter already performed implicitly; same for s_wb16.
  • libobs/util/source-profiler.c.h — four (uint8_t)((...) % FRAME_BUFFER_SIZE); the cast sits on the whole modulo expression (not on the addend), so the wrap-around stays identical.
  • libobs/util/profiler-io.c.h — the 16 sites only make the already-implicit uint64_t → double conversion explicit; (1. - (double)accu / (double)calls) keeps the original evaluation order, and the %-format arguments that were uint64_t / 1000. become (double)x / 1000. with the same value.
  • libobs/util/profiler.c.h, obs-audio-controls.c.h, media-remux.c.h, obs-output-interleave.c.h, pulseaudio-monitor-format.c.h — same pattern; (float)*cur * vol and (float)sum / (float)nr_samples preserve the promotions the C rules already applied, so no rounding changes.
  • libobs/util/platform-nix.c.h — (int)sysconf(...) keeps the pre-existing long → int narrowing (including a -1 failure value) and (useconds_t)remain_us is only reached in the < 1000000 branch, which is where the ternary already produced a useconds_t-safe value.

Checks I ran: clang-format --dry-run --Werror on the nine libobs/ files is clean. (clang-format also flags rust/obs-c-oracle/build.rs:13, but that is pre-existing on origin/master and the repo's lane only runs clang-format over its own file list.) The build claim itself I did not reproduce locally — this worktree has its submodules uninitialised, so soldr cargo build -p obs-c-oracle would not be the same configuration as CI's — the Fast Gate's oracle build (pending on this head) is the evidence to trust here.

docs/features.md: correctly no line, build tooling only. I am enabling auto-merge; the queue takes it when the Fast Gate and Tier 2 finish.

The clang build of the oracle (Apple clang on macOS, and clang on Linux)
surfaces -Wconversion diagnostics that the GCC Linux lane did not: explicit
casts only, at utf8.c.h, crc32.c.h, bitstream.c.h, obs-properties.c.h,
profiler-io.c.h and pulseaudio-monitor-format.c.h. The casts are the same
conversion the compiler already did implicitly, so no value changes.

Verified: CC=clang soldr cargo build -p obs-c-oracle and the default (GCC)
build are both clean; clang-format --dry-run --Werror clean.

Refs #2622, #516.
@zackees

zackees commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

Fixed the Rust Tests (macos-26) failure. The clang oracle build surfaces -Wconversion diagnostics the GCC Linux lane did not: the run failed at libobs/util/bitstream.c.h:47 (int -> uint16_t), and replaying the oracle's cc over every TU with CC=clang -Wno-error=<implicit*-conversion|shorten-64-to-32|float-conversion> in one pass enumerated the rest (utf8.c.h x8, crc32.c.h x2, obs-properties.c.h, profiler-io.c.h x3, pulseaudio-monitor-format.c.h).

New commit 02e91ca43: explicit casts only, the same conversion the compiler already did implicitly, so no value changes; no -Wno-* and no #pragma.

CC=clang soldr cargo build -p obs-c-oracle          # Finished, clean
soldr cargo build -p obs-c-oracle                   # GCC lane, clean
soldr cargo test -p obs-c-oracle --no-run           # Finished, clean
clang-format --dry-run --Werror <the 6 files>       # clean

Auto-merge is still on; re-queued for the merge gate.

@zackees
zackees added this pull request to the merge queue Oct 27, 2026
Merged via the queue into master with commit 7fb2d25 Oct 27, 2026
38 checks passed
@zackees
zackees deleted the infra/2622-c-oracle-format2-conversion branch October 27, 2026 14:29
MCPVOT pushed a commit to MCPVOT/obs-studio that referenced this pull request Oct 30, 2026
…jects on MinGW (obs-rust#516) (obs-rust#2651)

obs-rust#2632 added -Wconversion to the obs-c-oracle STRICT_FLAGS. MinGW's
isfinite(x) expands to fpclassify(x), whose float arm calls
__fpclassifyf(float) from a plain ternary, so passing (double)db
type-checks as a double->float conversion and the windows-gnu cross
build of the oracle fails under -Werror:

  libobs/media-io/audio-math.h:38:25: error: conversion from 'double'
  to 'float' may change value [-Werror=float-conversion]
  rust/obs-c-oracle/oracle/audio_controls.c (via libobs-ported-audio-controls.pch.h)

db is already a const float, so the cast was redundant: isfinite(db)
selects __fpclassifyf on MinGW, keeps the double arm on glibc/MSVC,
and produces identical code on every compiler.

Every other oracle translation unit for x86_64-pc-windows-gnu is clean
under the same flag set (167/171 compile; the 4 remaining need
build-script generated .inc files that are not part of the checkout).
MCPVOT pushed a commit to MCPVOT/obs-studio that referenced this pull request Oct 30, 2026
* ci: Compile the oracle's audio math with MinGW

Since -Wconversion joined the C oracle's STRICT_FLAGS (obs-rust#2632), the
windows-gnu oracle build stops in audio-math.h's db_to_mul():

  audio-math.h:38:25: error: conversion from 'double' to 'float' may
  change value [-Werror=float-conversion]

Add a test that compiles oracle/audio_math.c with build.rs's warning
flags and its windows-gnu flags, using the MinGW GCC soldr builds the
oracle with (15.3.0 here). It skips when no MinGW GCC is installed.
It fails until the windows-gnu flags handle MinGW's isfinite().

Refs obs-rust#2648.

* obs-c-oracle: Allow MinGW isfinite float casts

Since -Wconversion joined STRICT_FLAGS (obs-rust#2632), the windows-gnu build
of the oracle stops in audio-math.h's db_to_mul():

  audio-math.h:38:25: error: conversion from 'double' to 'float' may
  change value [-Werror=float-conversion]

MinGW's isfinite() is a type-generic macro whose float branch casts
its argument to float, and GCC checks that branch even for a double.
audio-math.h is a public header, so leave it alone and turn off
-Wfloat-conversion for the windows-gnu oracle only. The Linux GCC,
clang and macOS builds keep the check.

Fixes obs-rust#2648.

Local-Gate: v1 tree=1781bdd13482bba1ace2d93c6b343f5bf5fae7f8 secs=2389 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run
Ci-Attestation: {"at":1793119525,"gate":"rust/all/fmt","host":"linux-x86_64","key":"63fd6734b0385def17d28b77c052752f9bc93577f72508e9c77d1f4b69edcd1b","lane":"lint","parents":["b1eff2d60b0c233caf75d06ff2c75d76d35b2f44"],"secs":55,"stamp":"5f3882a13b4ec9bf30b28c3a2cf2541d","tree":"1781bdd13482bba1ace2d93c6b343f5bf5fae7f8","v":1,"via":"run"}
Ci-Attestation: {"at":1793119525,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"63fd6734b0385def17d28b77c052752f9bc93577f72508e9c77d1f4b69edcd1b","lane":"lint","parents":["b1eff2d60b0c233caf75d06ff2c75d76d35b2f44"],"secs":55,"stamp":"7ba1beec8efdd8003885c951e4c0c954","tree":"1781bdd13482bba1ace2d93c6b343f5bf5fae7f8","v":1,"via":"run"}
Ci-Attestation: {"at":1793119525,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"45ffcb11a4c69ee4fb8de46b4d314d5d4271e97e8a7555bbdf1a23e1572a234e","lane":"rust-test","parents":["b1eff2d60b0c233caf75d06ff2c75d76d35b2f44"],"secs":217,"stamp":"57fb2333b7c2b57f1c17a6966f1824cb","tree":"1781bdd13482bba1ace2d93c6b343f5bf5fae7f8","v":1,"via":"run"}
Ci-Attestation: {"at":1793119525,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"a5dbd80ed07189bdb58b9aa2f5c76537501e44be147c4f5b449861a01de660f7","lane":"cross","parents":["b1eff2d60b0c233caf75d06ff2c75d76d35b2f44"],"secs":82,"stamp":"726529b19feb277258756d46d6321a45","tree":"1781bdd13482bba1ace2d93c6b343f5bf5fae7f8","v":1,"via":"run"}
Ci-Attestation: {"at":1793119525,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"a5dbd80ed07189bdb58b9aa2f5c76537501e44be147c4f5b449861a01de660f7","lane":"cross","parents":["b1eff2d60b0c233caf75d06ff2c75d76d35b2f44"],"secs":82,"stamp":"0e111144496ee57d10cbcf8552d9d453","tree":"1781bdd13482bba1ace2d93c6b343f5bf5fae7f8","v":1,"via":"run"}
Ci-Attestation: {"at":1793119525,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"a5dbd80ed07189bdb58b9aa2f5c76537501e44be147c4f5b449861a01de660f7","lane":"cross","parents":["b1eff2d60b0c233caf75d06ff2c75d76d35b2f44"],"secs":82,"stamp":"55cf4c0d6c52a4572844dce27f051721","tree":"1781bdd13482bba1ace2d93c6b343f5bf5fae7f8","v":1,"via":"run"}
Ci-Attestation: {"at":1793119525,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"a5dbd80ed07189bdb58b9aa2f5c76537501e44be147c4f5b449861a01de660f7","lane":"cross","parents":["b1eff2d60b0c233caf75d06ff2c75d76d35b2f44"],"secs":82,"stamp":"34ae8fa379ae5761ac8c07391d0d4ca7","tree":"1781bdd13482bba1ace2d93c6b343f5bf5fae7f8","v":1,"via":"run"}
Ci-Attestation: {"at":1793119525,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"f07fb7478335ca7de18abdfaad6130439f5f75b149977cf0d547e5a16931cb3e","lane":"tier2-linux","parents":["b1eff2d60b0c233caf75d06ff2c75d76d35b2f44"],"secs":2034,"stamp":"492f336248dbc0fe482f1892fa955825","tree":"1781bdd13482bba1ace2d93c6b343f5bf5fae7f8","v":1,"via":"run"}
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.

build(c-oracle): Add -Wformat=2 and -Wconversion to STRICT_FLAGS

1 participant