Skip to content

Fix UB in when multiplying by zero#109

Open
mirthfulLee wants to merge 1 commit into
teoxoy:mainfrom
mirthfulLee:main
Open

Fix UB in when multiplying by zero#109
mirthfulLee wants to merge 1 commit into
teoxoy:mainfrom
mirthfulLee:main

Conversation

@mirthfulLee
Copy link
Copy Markdown

Summary

This PR fixes UB in SizeValue::mul when multiplication yields 0 (for example, rhs = 0).

Changes

  • Replace Self(unsafe { NonZeroU64::new_unchecked(val) }) to Self::new(val)
  • Add a regression test mul_zero_panic to ensure SizeValue::new(8).mul(0) panics.

Fix #108.

Copy link
Copy Markdown
Collaborator

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Main CI is failing unrelated to this change.

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.

UB in SizeValue::mul when multiplying by zero

2 participants