V775. It is odd that the BSTR data type is compared using a relational operator.

The analyzer detected a suspicious comparison operation involving an element of BSTR-type and relational operators: >, <, >=, <=.

BSTR (basic string or binary string) is a string data type used in COM, Automation, and Interop functions. This data type consists of a length prefix, a data string, and a terminal null.

The BSTR type is a pointer that always points to the first character of the data string, not the length prefix. For this reason, every BSTR object is unique and one BSTR object cannot be part of another, unlike ordinary strings.

Picture 1

However, an ordinary string can be part of a BSTR object (but never vice versa), so comparisons of the
"wchar_t* > BSTR" kind are valid.

Picture 8

Consider the following example:

void func(BSTR a, BSTR b)
  if (a > b)

This code is incorrect because comparison of the pointers 'a' and 'b' is a meaningless operation.

More about BSTR on MSDN.

According to Common Weakness Enumeration, potential errors found by using this diagnostic are classified as CWE-1023.

Bugs Found

Checked Projects
Collected Errors
12 668