Examples of errors detected by the V1065 diagnostic
V1065. Expression can be simplified: check similar operands.
DuckStation
V1065 Expression can be simplified, check 'm_display_texture_height' and similar operands. host_display.cpp 549
....
s32 m_display_texture_height = ....;
s32 m_display_texture_view_y = ....;
....
bool HostDisplay::WriteDisplayTextureToFile(....)
{
s32 read_y = m_display_texture_view_y;
s32 read_height = m_display_texture_view_height;
....
read_y = (m_display_texture_height - read_height) –
(m_display_texture_height - m_display_texture_view_y);
....
}
Ogre3D
V1065 Expression can be simplified: check similar operands. OgrePage.cpp 117
bool Page::isHeld() const
{
unsigned long nextFrame = Root::getSingleton().getNextFrameNumber();
unsigned long dist;
if (nextFrame < mFrameLastHeld)
{
// we must have wrapped around
dist = mFrameLastHeld +
(std::numeric_limits<unsigned long>::max() - mFrameLastHeld); // <=
}
else
dist = nextFrame - mFrameLastHeld;
// 5-frame tolerance
return dist <= 5;
}
Again, a very suspicious place. First, we can simplify the expression — it's enough to assign a value from std::numeric_limits to the dist variable. Secondly, if the condition is true, the dist variable is assigned a value that is obviously greater than 5.
Captain Blood
V1065 [CWE-682] Expression can be simplified, check 'bi' and similar operands. PreviewAnimation.cpp 146
PreviewAnimation::PreviewAnimation(....)
{
// ....
const int bw = 30;
const int bh = 30;
const int bi = 3;
const int cn = 9;
bar.r.w = 7 + (bw + bi)*cn + 7 - bi + 1 + (bw + bi) + 7 - bi + 1;
// ....
}