Skip to content

fl_gfx_rgbww: stale pointer-identity assertion after by-value contract migration (#2580) #2603

Closed

Description

@zackees

Symptom

fl_gfx_rgbww fails the "rgbww colorimetric profile get/set API" test case at tests/fl/gfx/rgbww.cpp:188:

FAIL: rgbww colorimetric profile get/set API at ../../tests/fl/gfx/rgbww.cpp:179
  ../../tests/fl/gfx/rgbww.cpp:188: after == &custom

Reproducible: any host build (bash test fl_gfx_rgbww --cpp).

Root cause

PR #2580 (CodeRabbit finding A4 from #2560) deliberately changed set_rgbww_colorimetric_profile() from stashing the caller's raw pointer to copying by value into a singleton-owned RgbwwColorimetricState::profile. The motivation was a dangling-pointer bug: callers commonly pass &local_var from setup(), and the stashed pointer was invalid once setup() returned.

src/fl/gfx/rgbww.cpp.hpp:87-100:

void set_rgbww_colorimetric_profile(const colorimetric_detail::RgbcctProfile* profile) FL_NOEXCEPT {
    RgbwwColorimetricState& state = fl::Singleton<RgbwwColorimetricState>::instance();
    if (profile == nullptr) { state.has_profile = false; return; }
    state.profile = *profile;        // ← copy by value
    state.has_profile = true;
}

const colorimetric_detail::RgbcctProfile* get_rgbww_colorimetric_profile() FL_NOEXCEPT {
    const RgbwwColorimetricState& state = fl::Singleton<RgbwwColorimetricState>::instance();
    return state.has_profile ? &state.profile : &kRgbwwDefaultProfile;
}

But the test at line 188 still asserts pointer identity with the caller's address:

const colorimetric_detail::RgbcctProfile* after = get_rgbww_colorimetric_profile();
FL_CHECK(after == &custom);  // ← FAILS — `after` is &state.profile, not &custom

If this assertion were to pass, it would mean the dangling-pointer bug had been reintroduced.

Fix

Update the test to assert the by-value contract instead of pointer identity:

FL_CHECK(after != nullptr);
FL_CHECK(after != &custom);              // distinct from caller's address
FL_CHECK(after != &kRgbwwDefaultProfile); // set actually took effect
FL_CHECK_CLOSE(after->warm_path.lum_w, 0.5f, 1e-6f);  // value flowed through

This tests what the implementation actually promises and would catch a regression to the dangling-pointer behavior.

Test plan

  • bash test fl_gfx_rgbww --cpp — passes (was red).
  • bash test fl_gfx_rgbww --debug — passes with ASAN/UBSAN/LSAN.

Surfaced by the Stop hook during an unrelated sweep on master.

Activity

  1. added a commit that references this issue on May 30, 2026
    2461b7d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions