Skip to content

frontend: enable -Wsign-conversion on the app target (#2625) - #2886

Closed
zackees wants to merge 11 commits into
masterfrom
infra/2625-conversion-frontend-sign
Closed

zackees wants to merge 11 commits into
masterfrom
infra/2625-conversion-frontend-sign

Conversation

@zackees

@zackees zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member

Refs #2625

Slice 1 of dropping the global conversion pins for the obs-studio app target:
-Wsign-conversion only. The other two groups (-Wconversion,
-Wfloat-conversion) stay pinned for this target and follow in their own PRs;
the flag list in frontend/CMakeLists.txt is the single target-level opt-in:

target_compile_options(obs-studio PRIVATE "$<$<COMPILE_LANG_AND_ID:CXX,AppleClang,Clang,GNU>:-Wsign-conversion>")

RED — 631e47772

build(frontend): enable the sign-conversion warnings on the app target (#2625)
only adds that flag. Replaying the frontend C++ units against the warm Tier 2
compile database with ci/warning_findings.py --select '*frontend.*' --language cxx reports 337 -Wsign-conversion findings (190 sites in 53
files)
, grouped by directory:

directory findings
frontend 14
frontend/components 33
frontend/dialogs 41
frontend/importers 2
frontend/oauth 1
frontend/plugin-manager 4
frontend/settings 44
frontend/utility 124
frontend/widgets 69
frontend/wizards 5
shared/properties-view, shared/qt/platform 10

The counts include the unity-build repetitions of the same header (e.g.
WHIPSimulcastEncoders.hpp is compiled into 23 units).

GREEN — 13fe40ab3

frontend: state the sign conversions the app target now reports (#2625)
states every conversion at its call site; no -Wno-*, no #pragma, no per-file
exemption, no vendored code touched. Same replay on the same tree: 0
-Wsign-conversion findings
(the other two groups keep their pins and are
unchanged).

What the fixes look like:

  • Loop counters and indices that feed size_t/uint32_t API parameters were
    widened where that was the natural type (size_t i for
    obs_enum_*_types, size_t idx for encoder slot counters,
    size_t asyncIdx/effectIdx), instead of adding a cast per call.
  • Values that stay signed at the API boundary are cast once
    (static_cast<uint32_t>(duration), static_cast<int>(obs_source_get_width(...))),
    never a negative-to-unsigned conversion without a guard.
  • Iterator arithmetic (vec.erase(begin + idx), begin() + iterationLimit)
    and Qt container indices use static_cast<std::ptrdiff_t> /
    static_cast<size_t>; OBSHotkeyWidget::RemoveEdit now takes
    std::ptrdiff_t, which is what std::distance already produced.
  • The four QColor packers share one adjustment: the shift lambda takes the
    int Qt hands it and does the mask in unsigned.
  • Bit-flag sites use 0u/1u (flags |= font.bold() ? OBS_FONT_BOLD : 0u,
    ~(1u << mixerIdx)) so the complement stays unsigned.
  • aspect_ratio() takes and returns uint32_t, matching every caller.

Verification

  • ./lint --fix then ./lint: == lane lint: ok.
  • Real build: ninja -j 12 obs-studio in the Tier 2 tree (which reconfigured
    from this branch's frontend/CMakeLists.txt, so the flag above is the one in
    the regenerated compile database) links frontend/obs-studio-rust-gui
    successfully.
  • Replay after that build: 0 findings for the selected frontend C++ units.

@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 (comment, not approval: this account is the PR author).

Verdict: sound and mechanical; one coverage gap to close before the off-Linux builds get it.

What I checked

  • RED → GREEN is real and in the right order. 631e47772 adds only the flag, 13fe40ab3 states the conversions. The target-level opt-in is a CXX-only genex, so the C units of the target, MSVC, and the macOS .mm units (OBJCXX, added by os-macos.cmake) are untouched, and the pins for -Wconversion/-Wfloat-conversion stay in place exactly as #2625's split describes. Flag ordering is right: the pins come from directory-scope add_compile_options (cmake/linux/compilerconfig.cmake), target options land after them on the command line, so -Wsign-conversion wins over -Wno-sign-conversion.
  • No suppression used. grep over the whole diff for -Wno, pragma, diagnostic, NOLINT: nothing. Matches #2625's "no #pragma GCC diagnostic ignored and no per-file -Wno-*".
  • The index/count casts are guarded at every site I traced. obs_property_list_item_disabled(p, size_t(cur_idx)) is reached only after cur_idx != -1 (ComboSelectToolbar, GameCaptureToolbar); the erase(begin() + ptrdiff_t(i)) changes are all inside i < size() loops; SimpleOutput::UpdateRecording's new size_t idx/idx2 are only post-incremented into a size_t parameter; ReorderFilter(..., size_t) already took size_t, so FilterOrderInfo's asyncIdx/effectIdx were the actual fix; WHIPSimulcastEncoders cannot underflow because layers <= 1 returns early; the size_t(index_) cast in AccessibleAlignmentCell::text is safe because the only constructor loop is for (int i = 0; i < cellCount; ++i) against a fixed 9-entry table.
  • Ledger correctly skipped — build tooling only, as #2625 states. No public header, test/, or C test edits.

One gap: the flag is target-wide, the evidence is Linux-only

The replay that produced "337 findings → 0" came from the Linux Tier 2 compile DB, but target_compile_options(obs-studio ...) applies to every C++ unit of the target, including units Linux never compiles. I walked frontend/build/source-sets.json against the Linux source sets:

set unit state
MACOS frontend.macos+.hpp.cpp (OBSPermissions.cpp.hpp) clean, no integer conversions
SPARKLE frontend.sparkle+.hpp.cpp (MacUpdateThread.cpp.hpp) clean
FREEBSD frontend.freebsd+.hpp.cpp (CrashHandler_FreeBSD.cpp.hpp) clean
FREEBSD_PLUGIN_MANAGER frontend.plugin-manager-bsd+.hpp.cpp two hits
WINDOWS all MSVC, excluded by the genex

frontend/plugin-manager/PluginModuleLoader_BSD.cpp.hpp:124 and :190:

int bufferSize = os_get_config_path(userConfigPath.data(), userConfigPath.size(), nullptr);
if (bufferSize > 0) {
    userConfigPath.resize(bufferSize);   // int -> size_type

That is -Wsign-conversion, and FreeBSD is Clang, so the genex matches and -Werror turns it into a build failure. Since FreeBSD is not in PR CI and the macOS GUI build only runs on schedule/release, PR CI cannot see this. Two-line fix, guarded by bufferSize > 0:

userConfigPath.resize(static_cast<size_t>(bufferSize));

(The .mm macOS units are fine for the reason above; frontend.whatsnew+ and frontend.native-event-filter+ are also compiled by the Linux sets, so the What's New / event-filter C++ is covered by the replay.)

Nits, not blockers

  • OBSBasicTransform: widthForFlip/heightForFlip moving from uint32_t to int is the right type (it matches obs_sceneitem_crop's int fields and your crop.left = ui->cropLeft->value() change), but it is the one hunk where the value can differ: with crop.left + crop.right > sourceWidth the old unsigned expression wrapped to a huge positive and the new one goes negative, so shiftX/shiftY differ in that corner. libobs already treats an over-crop as "crops all of it" (obs_scene_cropped_size), so negative reads better — just confirm it is intended rather than incidental.
  • int sdrWhiteLevel / int hdrNominalPeakLevel are narrowing casts from config_get_uint. Fine while the spinbox range stays under INT_MAX; if you read #2625's "a narrowing cast is only used where the range is provably in bounds" strictly, a bound check or a comment would settle it.

State at review time: uv run -m workflow.coordinator checks obs-studio 2886 → 25 passed, 0 failed, 8 running (Rust Tier 2 Linux queued, Rust Tests/Tier 2 macOS in flight), so the enqueue follows once they finish rather than now.

@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Blocked on #2887: the macOS Tier 2 lane fails in libobs/obs-cocoa.m.h (-Wsign-conversion at 161, 727, 836, 861), which is the libobs Cocoa ratchet #2887 states — not a finding in this PR's frontend slice. I will rebase this onto origin/master and re-run once #2887 merges.

@zackees
zackees force-pushed the infra/2625-conversion-frontend-sign branch from 13fe40a to ae6b165 Compare October 29, 2026 08:29
@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Stacked on #2887 (50628d634).

The macOS Tier 2 lane on the previous head (13fe40ab3) failed only in libobs/obs-cocoa.m.h — the four conversions #2887 fixes (161, 727, 836, 861), which #2887's earlier head had one of left over (837, the int key code passed to UCKeyTranslate's UInt16; now fixed there too). This PR's own change is unaffected by that file, but its lane cannot get past it, so the two commits are rebased on #2887's head to get a clean macOS verdict on the frontend flag change.

@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Restacked: #2887 was folded into #2897 (2da11e3e2), so this branch now sits on #2897's two commits (cocoa + the enum -> int seam wave) instead of the old single cocoa commit. The lane that was red under 13fe40ab3 failed on both halves; #2897's head is the first base that can be green, so this PR's macOS verdict comes from stacking there. After #2897 merges I rebase these two commits onto origin/master and retarget.

@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Coordinator: the two red checks on this PR are not from its diff. Build 🧱 / Rust Tier 2 (macos-26) fails in libobs/obs-cocoa.m.h (lines 161, 727, 836, 861) on master, from the #2625 ratchet that #2877 landed with a Linux-only replay; #2887 fixes those four sites and its macOS lane then exposes 19 more in obs-scene.c.h, obs-source-deinterlace.c.h, obs-display.c.h, obs-canvas.c.h (see my comment there). CI Gate ✅ is only reporting that failure.

Nothing to change in this PR. One thing to expect: its own AppleClang evidence is a Linux replay too (337 findings from the Tier 2 Linux compile database), so once libobs compiles on macOS the frontend TUs this PR converts may report macOS-only diagnostics of their own. Re-running the macOS lane after the libobs gap closes is the honest check; I will rebase this branch then.

@zackees
zackees force-pushed the infra/2625-conversion-frontend-sign branch from 4a62546 to 6eeb347 Compare October 29, 2026 08:55
The first green attempt still failed: the same #ifdef-only blind spot hides
four more -Wsign-conversion diagnostics (CGLTexImageIOSurface2D takes GLsizei
widths from uint32_t texture fields) and two -Wfloat-conversion ones (CGSize
CGFloat dimensions into device_texture_create's uint32_t). State them at the
call; values unchanged.
The libobs ratchet (#2877) had the same Linux-only replay blind spot: the
macOS Tier 2 lane then reported CFIndex -> size_t (dstr_reserve), obs_key_t ->
int (mouse button index), int -> UInt16 (UCKeyTranslate key code) and
UniCharCount -> CFIndex (CFStringCreateWithCharactersNoCopy). State each at
the call; values unchanged.
-Wsign-conversion on the macOS Tier 2 lane rejects strlen()'s size_t as the
CFIndex byte count; cast at the boundary.
-RED: `Rust Tier 2 (macos-26)` on `07340d52e` + #2887's cocoa fix
(job 123343547757) reports 19 `-Werror,-Wsign-conversion` /
`-Wimplicit-int-conversion` diagnostics in the four Rust seam call
sites below: `enum video_format`, `obs_bounds_type`, `obs_scale_type`,
`obs_blending_method`, `obs_blending_type`, `gs_color_space` and
`obs_deinterlace_mode` passed to a helper the port declares with an
`int` parameter. AppleClang gives an all-non-negative enum an unsigned
underlying type; GCC and Linux clang keep `int`, so #2877's replay of
the same TUs could not see them.

-GREEN: state the conversion at each call site, leaving the seam
signatures and the Rust `c_int` ABI unchanged. Two further sites of the
same class (obs_canvas_draw_technique()/reads_white_level() in
obs.c.h, the deinterlace mode-change call) are cast with them so the
next macOS wave does not re-report the group.

No Rust or cmocka change: no signature moved, and the casts are
behaviour-neutral (the values are enum members, not sentinels).
The next macOS Tier 2 wave after b43279b reports 19 more
'enum -> int' conversions, all in libobs/obs-source.c.h: the monitoring
type fed to obs_source_audio_place_outputs(), the async and sync render
plans' gs_color_space arguments, and src->format into
obs_source_frame_copy_plan().

AppleClang gives all-positive enums an unsigned underlying type; the
seam helpers take int (the Rust c_int ABI carries -1 sentinels), so each
call site is an implicit conversion visible only on Apple platforms.
Cast at each call site; signatures, Rust ABI and tests do not move.
@zackees
zackees force-pushed the infra/2625-conversion-frontend-sign branch from 6eeb347 to 57abc6a Compare October 29, 2026 09:32
@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Rebased onto the fix/2896 tip (c4e270448), so this branch now carries the whole conversion stack it depends on: #2892's three commits including fa2550b83 (CoreAudio strlen -> CFIndex) and #2897's two seam commits.

The Rust Tier 2 (macos-26) failure was that missing CoreAudio commit, not this PR's frontend flag:

libobs/audio-monitoring/osx/coreaudio-output.c.h:180:54: error: implicit conversion changes signedness:
  'unsigned long' to 'CFIndex' (aka 'long') [-Werror,-Wsign-conversion]

This branch was cut from an older #2892 head (two of its three commits), so the lane compiled a CoreAudio TU the stack had not yet fixed. The stale build(libobs): state the enum -> int seam conversions copy (b43279b18) was dropped in favour of #2897's e99ef026f/c4e270448. New head 57abc6a69; diff against master is unchanged apart from the stack it sits on.

@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Coordinator note for head 57abc6a6 — the Tier 2 macOS failure is the same wave #2900 measured, not the CoreAudio commit:

build(libobs) ... libobs/obs-source.c.h:3167:65: error: implicit conversion changes signedness: 'const enum video_format' to 'int' [-Werror,-Wsign-conversion]
libobs/obs-source.c.h:3192:66, 3192:81 (video_range_type)
libobs/obs-source.c.h:3263:20, 3308:65, 3333:66, 3333:81 (video_range_type)
libobs/obs-source.c.h:3407:65, 3432:66, 3432:81 (video_range_type)

Job 123373458423 (run 40850391064), step "Validate Tier 2 on macOS", 09:49Z, ** BUILD FAILED **. Ten sites, all video_format / video_range_type into int. The C++ app nightly in #2900 saw seven of these in the same file with -Wsign-conversion from the frontend side; this lane compiles the same file, so the count differs by the columns that only the C build reaches.

Consequence for the stack: this lane cannot be green until the obs-source.c.h seams land, and #2900 carries them above this PR. So the merge order has to put those seams below #2886 — 2892 → 2897 → the obs-source.c.h conversion commit → 2886 → 2900 — or the same ten sites fail again after the queue gets 2886. Nothing to do to this branch for it; I am leaving the stack alone because you are mid-series on it.

@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

CI follow-up: Build 🧱 / Rust Tier 2 (macos-26) failed on this PR (run 40850391064, job 123373458423) with ten -Werror,-Wsign-conversion diagnostics in libobs/obs-source.c.h:

obs-source.c.h:3167:65: error: implicit conversion changes signedness: 'const enum video_format' to 'int'
obs-source.c.h:3192:66: error: implicit conversion changes signedness: 'const enum video_format' to 'int'
obs-source.c.h:3192:81: error: implicit conversion changes signedness: 'const enum video_range_type' to 'int'
obs-source.c.h:3263:20: error: implicit conversion changes signedness: 'const enum video_format' to 'int'
obs-source.c.h:3308:65: error: implicit conversion changes signedness: 'const enum video_format' to 'int'
obs-source.c.h:3333:66: error: implicit conversion changes signedness: 'const enum video_format' to 'int'
obs-source.c.h:3333:81: error: implicit conversion changes signedness: 'const enum video_range_type' to 'int'
obs-source.c.h:3407:65: error: implicit conversion changes signedness: 'const enum video_format' to 'int'
obs-source.c.h:3432:66: error: implicit conversion changes signedness: 'const enum video_format' to 'int'
obs-source.c.h:3432:81: error: implicit conversion changes signedness: 'const enum video_range_type' to 'int'

The libobs target already opts into -Wconversion;-Wsign-conversion;-Wfloat-conversion, and the four *_video* entry points plus frame_copy_shape passed the enum video_format / enum video_range_type straight into int fields and int parameters. The conversions are now stated at those seven call sites ((int)frame->format, (int)frame->range), no behaviour change.

Evidence: ./lint ok (45.0 s). macOS Tier 2 re-run on ac5bce7 is the verification; local clang on Linux does not see this AppleClang diagnostic.

@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Wave 2 of the same lane (run 40858510563, job 123399828559) surfaced the neighbouring libobs seams that the first fix let the compiler reach:

obs-output.c.h:1084:51 / 1092:58 / 1131:63 / 1189:63: 'enum obs_encoder_type' -> int
obs-output.c.h:1606:30: 'int' -> 'uint16_t'
obs-video.c.h:122:24: 'const enum gs_color_space' -> int
obs-video.c.h:267:26: 'enum obs_scale_type' -> int
obs-video-gpu-encode.c.h:254:40: 'const enum video_format' -> int

Stated at those call sites: (int)encoder->info.type and (int)info->format at the gate predicates, (uint16_t)(captionData << 8) on the caption byte swap (the shift promotes to int, the value is one byte's worth of data), (int)mix->render_space / (int)mix->ovi.scale_type on the mix-reuse keys. No behaviour change.

./lint ok (44.3 s); macOS Tier 2 on cba048e is the verification.

@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Wave 3 (job 123410539596, head cba048e):

obs-hotkey-name-map.c.h:110:10: error: implicit conversion changes signedness: 'int' to 'obs_key_t' (aka 'enum obs_key')

obs_key_from_name recovers the key from the int out-parameter of obs_hotkey_name_map_lookup; the conversion is stated as return (obs_key_t)v;. ./lint ok (43.4 s).

@zackees
zackees force-pushed the infra/2625-conversion-frontend-sign branch from a90cf82 to 7bde56a Compare October 29, 2026 11:39
@zackees
zackees added this pull request to the merge queue Oct 29, 2026
@zackees
zackees removed this pull request from the merge queue due to a manual request Oct 29, 2026
@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Dequeued from the merge queue: this branch and #2900 carry the same patch series (the #2879/#2896/#2625 conversion commits, rebuilt with different hashes — e.g. libobs: state the four macOS Cocoa conversions too and frontend: state the sign conversions the app target now reports appear in both). #2900 is position 1 in the queue and includes this branch's series, so the queue marked this entry UNMERGEABLE against it.

Waiting for #2900 to merge, then I will rebase the commits unique to this branch (libobs: state the Cocoa CFIndex and pointer-difference conversions) onto origin/master, retarget and reopen, or close it as superseded if the remaining diff is empty.

@zackees
zackees added this pull request to the merge queue Oct 29, 2026
@zackees
zackees removed this pull request from the merge queue due to a manual request Oct 29, 2026
@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Superseded by master: rebasing onto 5298ad7 dropped every commit on this branch as already upstream. frontend/CMakeLists.txt:38 carries the -Wsign-conversion opt-in and the call-site casts are in the same tree, landed with the #2879/#2900 merge group. Nothing left here, closing.

@zackees zackees closed this Oct 29, 2026
@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Closing: everything this PR carried has landed on master already.

#2900's squash (5298ad7ec build(libobs): state the source frame-copy seam conversions (#2879)) incorporated this branch's commits along with the libobs seam fixes, so after rebasing onto current master this branch is empty:

$ git rev-list --count origin/master..HEAD
0

The app-target flag this PR was opened for is on master (frontend/CMakeLists.txt:38, -Wsign-conversion on obs-studio), and the macOS Tier 2 cleanup that this PR chased through four failing waves is in the same squash (obs-source.c.h, obs-output.c.h, obs-video.c.h, obs-video-gpu-encode.c.h, obs-hotkey-name-map.c.h, util/platform-cocoa.m.h).

Verification that the lane is fixed: Build 🧱 / Rust Tier 2 (macos-26) passed on 7bde56a (run 40867131825, job 123428545024) after the last wave, and the merge-group run for #2900 then landed the same tree on master.

@obs-rust-project-manager obs-rust-project-manager Bot moved this from Needs fix to Done in obs-rust Multiview Oct 29, 2026
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