Skip to content

Commit da80018

Browse files
Undefined-behaviour fix: safely call std::isspace in CompletionData (microsoft#5564)
### What was fixed [CompletionData.cpp](cci:7://file:///c:/Users/T2430514/Downloads/winget-cli/src/AppInstallerCLICore/CompletionData.cpp:0:0-0:0) passed a potentially negative `char` to `std::isspace`, invoking undefined behaviour on non-ASCII input (signed `char` platforms). This occasionally caused crashes or incorrect cursor repositioning when autocompleting commands containing UTF-8 characters. ### How it was fixed The character is now explicitly cast to `unsigned char` before the `std::isspace` check: ```cpp !std::isspace(static_cast<unsigned char>(commandLine[cursor - 1])) ``` This aligns with standard C++ guidance and makes the completion logic robust across all locales. ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/microsoft/winget-cli/pull/5564) Co-authored-by: Odio Marcelino <[email protected]>
1 parent 8115f41 commit da80018

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/AppInstallerCLICore/CompletionData.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ namespace AppInstaller::CLI
5959
// very few users are likely to put any spaces at the front of their statements, let alone many.
6060
else
6161
{
62-
for (; cursor > 0 && !std::isspace(commandLine[cursor - 1]); --cursor);
62+
for (; cursor > 0 && !std::isspace(static_cast<unsigned char>(commandLine[cursor - 1])); --cursor);
6363

6464
AICLI_LOG(CLI, Info, << "Cursor position moved to '" << cursor << '\'');
6565

0 commit comments

Comments
 (0)