Warning C6400

Using 'function name' to perform a case-insensitive compare to constant string 'string name'. Yields unexpected results in non-English locales

Remarks

This warning indicates that a case-insensitive comparison to a constant string is being done in a locale-dependent way. It appears that a locale-independent comparison was intended.

The typical consequence of this defect is incorrect behavior in non-English speaking locales. For example, in Turkish, ".gif" won't match ".GIF"; in Vietnamese, "LookUp" won't match "LOOKUP".

String comparisons should typically be performed with the CompareString function. To perform a locale-independent comparison on Windows XP, the first parameter should be the constant LOCALE_INVARIANT.

Code analysis name: LOCALE_DEPENDENT_CONSTANT_STRING_COMPARISON

Example

The following code generates this warning:

#include <windows.h>
int f(char *ext)
{
  // code...
  return (lstrcmpi(ext, TEXT("gif")) == 0);
}

To correct this warning, perform a locale-independent test for whether char *ext matches "gif" ignoring upper/lower case differences, use the following code:

#include <windows.h>
int f(char *ext)
{
  // code...
  return (CompareString(
                        LOCALE_INVARIANT,
                        NORM_IGNORECASE,
                        ext,
                        -1,
                        TEXT ("gif"),
                        -1) == CSTR_EQUAL);
}

See also

CompareString