Examples of errors detected by the V698 diagnostic.


V698. strcmp()-like functions can return not only the values -1, 0 and 1, but any values.


.NET CoreCLR

V698 Expression 'memcmp(....) == -1' is incorrect. This function can return not only the value '-1', but any negative value. Consider using 'memcmp(....) < 0' instead. sos util.cpp 142


bool operator( )(const GUID& _Key1, const GUID& _Key2) const
  { return memcmp(&_Key1, &_Key2, sizeof(GUID)) == -1; }

In cases like this, you should check one of the three states: '< 0', '0', or '> 0'.



Do you make errors in the code?

Check your code
with PVS-Studio

Static code analysis
for C, C++ and C#

goto PVS-Studio;