Skip to content

Fix u64 overflow in PWM frequency constraint check - #60

Merged
harshverma27 merged 1 commit into
mainfrom
claude/issue-50-fix
Jun 30, 2026
Merged

Fix u64 overflow in PWM frequency constraint check#60
harshverma27 merged 1 commit into
mainfrom
claude/issue-50-fix

Conversation

@harshverma27

Copy link
Copy Markdown
Owner

Fixes #50

Summary

  • clocks::validate's PWM timing reachability check computed (freq as u64) * arr_plus_one with plain multiplication. freq comes straight from TOML as an i64 and can be arbitrarily large (e.g. a typo'd extra digit), so this multiplication could overflow u64 — panicking in debug builds, or silently wrapping to a small value in release that could wrongly pass the > timer_clk check, letting an invalid PWM config through with no diagnostic.
  • Switched to checked_mul, treating an overflowing product as proof the frequency is unreachable (it necessarily is, since the real product would dwarf any realistic timer clock).

Test plan

  • Added huge_pwm_frequency_is_a_clock_constraint_not_a_panic with frequency_hz = 9000000000000000000.
  • cargo test -p nucleus-compiler --lib — 148 passed.
  • cargo clippy -p nucleus-compiler --all-targets -- -D warnings — clean.
  • cargo fmt --all -- --check — clean.

Generated by Claude Code

(freq as u64) * arr_plus_one overflowed u64 silently for a large TOML
i64 frequency_hz value (a debug-build panic, or a wrapped product that
could wrongly pass the > timer_clk check in release), letting invalid
PWM configs through with no diagnostic. Use checked_mul and treat an
overflowing product as proof the frequency is unreachable.
@harshverma27
harshverma27 merged commit 5756caa into main Jun 30, 2026
5 checks passed
@harshverma27
harshverma27 deleted the claude/issue-50-fix branch June 30, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

u64 overflow in PWM frequency constraint check silently passes invalid configs

2 participants