-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
C Drivers
-
None
-
None
-
None
-
None
-
None
-
None
Scope
Fix string conversion warnings when UNICODE is defined on MSVC. Either use the non-Unicode A functions (i.e. don't bother with Unicode) or use the generic functions to follow MSVC recommendations.
Background
Some Windows APIs offer multiple forms for string encoding:
#ifdef UNICODE #define SetWindowText SetWindowTextW #else #define SetWindowText SetWindowTextA #endif // !UNICODE
The W form uses 2-byte wide characters. The A form uses 1-byte characters. The generic form (no suffix) depends on UNICODE being defined.
The C driver has some calls to the generic forms. This results in several warnings when UNICODE is defined. Examples:
C:\code\mongo-c-driver\src\libmongoc\src\mongoc\mongoc-client.c(114): warning C4133: 'function': incompatible types - from 'PWSTR' to 'const char *'
I expect this could cause a correctness issue if UNICODE is defined. E.g. test-libmongoc.exe crashes when built with UNICODE defined.
MSVC docs recommend the generic form:
New Windows applications should use Unicode to avoid the inconsistencies of varied code pages and for ease of localization. They should be written with generic functions, and should define UNICODE to compile the functions into Unicode functions.
But I am unsure if supporting wide-strings is valuable. I expect relevant strings are unlikely to be non-ASCII (e.g. file names, hostnames, DNS results). IMO: use the A form for simplicity unless there is reason to believe the W forms are needed.