1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

0032903: Coding Rules - eliminate MSVC warning C26451 on VS2019/C++20

Put explicit type casting to avoid:
Warning C26451 Arithmetic overflow: Using operator '-' on a 4 byte
value and then casting the result to a 8 byte value.
Cast the value to the wider type before calling operator '-' to avoid overflow (io.2).
This commit is contained in:
ddzama
2022-03-29 16:32:46 +03:00
committed by smoskvin
parent 9416ba5fb0
commit 4e1b5fcbf0
4 changed files with 28 additions and 23 deletions

View File

@@ -253,14 +253,16 @@ inline Standard_Real RealPart (const Standard_Real Value)
// If input value is out of valid range for integers,
// minimal or maximal possible integer is returned.
//-------------------------------------------------------------------
inline Standard_Integer RealToInt (const Standard_Real Value)
inline Standard_Integer RealToInt (const Standard_Real theValue)
{
// Note that on WNT under MS VC++ 8.0 conversion of double value less
// than INT_MIN or greater than INT_MAX to integer will cause signal
// "Floating point multiple trap" (OCC17861)
return Value < INT_MIN ? INT_MIN
: Value > INT_MAX ? INT_MAX
: (Standard_Integer)Value;
return theValue < static_cast<Standard_Real>(INT_MIN)
? static_cast<Standard_Integer>(INT_MIN)
: (theValue > static_cast<Standard_Real>(INT_MAX)
? static_cast<Standard_Integer>(INT_MAX)
: static_cast<Standard_Integer>(theValue));
}
// =======================================================================