Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V775. It is suspicious that the BSTR...
menu mobile close menu
Additional information
toggle menu Contents

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

Dec 05 2016

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.

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.

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.

This diagnostic is classified as: