Skip to content

Commit

Permalink
cast to larger type before doing arithmetic to avoid signed integer o…
Browse files Browse the repository at this point in the history
…verflow

https://godbolt.org/z/soTad4zEq

this godbolt links shows that it is UB to multiply then cast if the amount is large enough
  • Loading branch information
ZXShady committed Sep 29, 2024
1 parent ef81fbd commit 03168dd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/CSFML/System/Time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ sfTime sfSeconds(float amount)
////////////////////////////////////////////////////////////
sfTime sfMilliseconds(int32_t amount)
{
return {static_cast<int64_t>(amount * 1000)};
return {int64_t{amount} * 1000};
}


Expand Down

0 comments on commit 03168dd

Please sign in to comment.