Skip to content

Attempt to multiply with overflow #82

Closed Answered by BurntSushi
azzamsa asked this question in Q&A
Discussion options

You must be logged in to vote

date.year() returns an i16. In this case, 1442. Multiplying that by 354 gives 510468, which overflows i16. Chrono's date.year() returns an i32, which doesn't result in an overflow here. So a simple fix is to convert to i32 and then multiply: ((354 * i32::from(date.year())).

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@azzamsa
Comment options

@BurntSushi
Comment options

Answer selected by azzamsa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants