Undefined-behaviour fix: safely call std::isspace in CompletionData by mohiuddin-khan-shiam · Pull Request #5564 · microsoft/winget-cli
and others added 2 commits
June 29, 2025 19:00What 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. Co-Authored-By: S. M. Mohiuddin Khan Shiam <147746955+mohiuddin-khan-shiam@users.noreply.github.com>
### 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters