Support Board
Date/Time: Fri, 29 Nov 2024 03:46:20 +0000
Post From: Suggestion to remove compiler warnings for sierrachart.h and SCString.h
[2023-03-11 07:12:26] |
User719512 - Posts: 267 |
Hi Sierra Engineering, Suggestion to remove compiler warnings for sierrachart.h and SCString.h when compiling with Visual Studio. When compiling with Visual Studio, I get warnings like this: 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). Suggested fixes are as follows sierrachart.h: Use floats for comparisons. int Round(float Number) { int IntegerResult = static_cast <int>(Number); if ((Number > 0.0f) && ((Number-IntegerResult) >= 0.5f)) return ++IntegerResult; else if ((Number < 0.0f) && ((Number - IntegerResult) <= -0.5f)) return --IntegerResult; return IntegerResult; } int64_t Round64(double Number) { int64_t IntegerResult = static_cast <int64_t>(Number); if ((Number > 0.0f) && ((Number - IntegerResult) >= 0.5f)) return ++IntegerResult; else if ((Number < 0.0f) && ((Number - IntegerResult) <= -0.5f)) return --IntegerResult; return IntegerResult; } SCString.h: Use static_cast<rsize_t> for all 5 strncpy_s calls (1 shown below) strncpy_s(m_String, static_cast<rsize_t>(BufferSize), SourceString, static_cast<rsize_t>(StringLength)); SCString.h: Use static_cast<size_t> to remove lnt-arithmetic-overflow: A sub-expression may overflow before being assigned to a wider type. vsprintf_s ( NewStringBuffer + PriorLength , static_cast<size_t>(TargetLength) + 1 , FormatString , ArgumentList ); Date Time Of Last Edit: 2023-03-11 07:32:06
|