Skip to content

fix(fx): saturate TimeWarp steps that do not fit in int32 - #5302

Merged
zackees merged 2 commits into
FastLED:masterfrom
emincan2000:timewarp-int32-clamp
Dec 3, 2026
Merged

zackees merged 2 commits into
FastLED:masterfrom
emincan2000:timewarp-int32-clamp

Conversation

@emincan2000

@emincan2000 emincan2000 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

TimeWarp::applyExact() clamps the scaled step to 2147483647.0f before casting it to i32. But 2147483647.0f isn't representable as a float and rounds to 2147483648.0f. Every clamped value is therefore 2^31, making the cast undefined. On x86 the cast returns INT32_MIN. The step then looks negative, so the rollover protection resets the time to 0 instead of moving it forward. This happens when a single update covers more than 2^31 scaled ms, for example 3000000000 ms at speed 1 or 3000000 ms at speed 1000. The negative branch also computes -diff, which overflows when diff is INT32_MIN.

The fix compares against 2^31 directly and saturates the step to INT32_MAX or INT32_MIN. It also computes the absolute value in unsigned arithmetic. Steps inside the int32 range are cast exactly as before.

I added a subcase in tests/fl/fx/time.cpp to cover these cases. I also built time.cpp.hpp on its own with UBSan float-cast-overflow and ran the existing checks along with the new ones. With the old code, UBSan reports both overflows and the two forward cases give 0. The new code passes all the checks with no reports. I didn't run the full FastLED test runner.

Summary by CodeRabbit

  • Bug Fixes
    • Large forward and reverse time updates now stay within the supported range, avoiding overflow and producing consistent results at normal and accelerated speeds.
  • Tests
    • Added coverage for time updates that exceed the supported range.

applyExact() clamped the scaled step to 2147483647.0f, which is 2^31 as a
float, so the cast to i32 was undefined. On x86 it gives INT32_MIN and the
time was reset to 0 instead of moving forward. Also negate diff without
overflowing when it is INT32_MIN.
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

Parsing warnings: 1

Validation error: Unrecognized key: "enabled" at "reviews.pre_merge_checks"
Configuration instructions

  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

No actionable comments were generated in the recent review.

Walkthrough

TimeWarp::applyExact now saturates scaled time at the i32 limits before conversion and computes negative delta magnitude with unsigned arithmetic. Tests cover large forward updates at normal and 1000× speed, plus a large reverse update.

Changes: TimeWarp integer boundary handling

Layer / File(s) Summary
Saturation and boundary tests
src/fl/fx/time.cpp.hpp, tests/unit/fl/fx/time.cpp
applyExact saturates scaled time before conversion and computes negative delta magnitude with unsigned arithmetic. Tests cover large forward updates at normal and 1000× speed, and a large reverse update.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: zackees

Merge Risk: Minimal · up to 3fea6

This change fixes TimeWarp so very large time steps saturate correctly instead of overflowing or wrapping negative. Boundary tests were added. No merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: TimeWarp scaled steps that exceed the int32 range are saturated. The raw summary and PR objectives both describe a saturation fix in TimeWarp::applyExact, with a match…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: TimeWarp scaled steps that exceed the int32 range are saturated. The raw summary and PR objectives both describe a saturation fix in TimeWarp::applyExact, with a matching test addition. The title is specific and related to the changeset, so it passes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 6a74988 and 3fea6df.

Files selected for processing: 1

  • tests/unit/fl/fx/time.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 19, 2026
@github-actions github-actions Bot added sanitized Title, body and conversation screened; review text requires separate screening. and removed sanitized Title, body and conversation screened; review text requires separate screening. labels Nov 19, 2026
@github-actions github-actions Bot added sanitized Title, body and conversation screened; review text requires separate screening. and removed sanitized Title, body and conversation screened; review text requires separate screening. labels Nov 19, 2026
@github-actions github-actions Bot added sanitized Title, body and conversation screened; review text requires separate screening. and removed sanitized Title, body and conversation screened; review text requires separate screening. labels Nov 24, 2026
@github-actions github-actions Bot added sanitized Title, body and conversation screened; review text requires separate screening. and removed sanitized Title, body and conversation screened; review text requires separate screening. labels Nov 24, 2026
@zackees
zackees added this pull request to the merge queue Dec 3, 2026
Merged via the queue into FastLED:master with commit f8f23f8 Dec 3, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sanitized Title, body and conversation screened; review text requires separate screening.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

2 participants