Skip to content

Fix CodeQL warnings after _wsetlocale() changes - #6179

Merged
Stephan T. Lavavej (StephanTLavavej) merged 2 commits into
microsoft:mainfrom
StephanTLavavej:codeql
Mar 27, 2026
Merged

Fix CodeQL warnings after _wsetlocale() changes#6179
Stephan T. Lavavej (StephanTLavavej) merged 2 commits into
microsoft:mainfrom
StephanTLavavej:codeql

Conversation

@StephanTLavavej

Copy link
Copy Markdown
Member

Fixes internal VSO-2845667 and VSO-2845668.

CodeQL is emitting SM02986: cpp/incorrect-string-type-conversion, saying "Conversion from char * to __wchar_t *. Use of invalid string can lead to undefined behavior." for <xlocinfo> and "Conversion from const char * to const __wchar_t *. Use of invalid string can lead to undefined behavior." for locale0.cpp.

These warnings are desirable, we're just doing something that's intentionally sketchy-looking but correct. Accordingly, I'm adding suppression comments, citing #5781 where these changes were introduced.

CodeQL appears to warn only when reinterpret_casting from char* to wchar_t*, not the reverse (possibly because casts to char* are very common). Just in case, I am additionally adding the suppression to the reinterpret_cast<char*> where we actually store the wide string.

@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) moved this from Final Review to Ready To Merge in STL Code Reviews Mar 24, 2026
@StephanTLavavej

Copy link
Copy Markdown
Member Author

I'm mirroring this to the MSVC-internal repo. Please notify me if any further changes are pushed, otherwise no action is required.

@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) moved this from Ready To Merge to Merging in STL Code Reviews Mar 26, 2026
@StephanTLavavej
Stephan T. Lavavej (StephanTLavavej) merged commit 49a58a1 into microsoft:main Mar 27, 2026
49 checks passed
@github-project-automation github-project-automation Bot moved this from Merging to Done in STL Code Reviews Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Something can be improved

2 participants