summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorleha-bot <leha-bot@yandex.ru>2024-01-05 18:56:33 (GMT)
committerBrad King <brad.king@kitware.com>2024-01-05 19:36:43 (GMT)
commit5e8c176e2ac38617b35eb9152ef76d949ef736e8 (patch)
treede6b59fc10aec1792f851b9cda377619320934e7 /Source
parent1f66051983ef0bdefa5de139fa9013830a4c3047 (diff)
downloadCMake-5e8c176e2ac38617b35eb9152ef76d949ef736e8.zip
CMake-5e8c176e2ac38617b35eb9152ef76d949ef736e8.tar.gz
CMake-5e8c176e2ac38617b35eb9152ef76d949ef736e8.tar.bz2
cmExecuteProcessCommand: Cast c to unsigned char before cast to int
As the 'char' type may be either signed, or unsigned, there are some clashes between C Standard library functions and actual characters while casting it to int directly. In case the 'char' type was signed, the casted to int result value may be extended to full negative digit which may be out of range of isspace() function (e.g. , for MSVC implementation, which checks it for '> -1', and throwing an assertion failure on fail). Fixes: #25561
Diffstat (limited to 'Source')
-rw-r--r--Source/cmExecuteProcessCommand.cxx6
1 files changed, 5 insertions, 1 deletions
diff --git a/Source/cmExecuteProcessCommand.cxx b/Source/cmExecuteProcessCommand.cxx
index e764545..483a601 100644
--- a/Source/cmExecuteProcessCommand.cxx
+++ b/Source/cmExecuteProcessCommand.cxx
@@ -35,7 +35,11 @@
namespace {
bool cmExecuteProcessCommandIsWhitespace(char c)
{
- return (isspace(static_cast<int>(c)) || c == '\n' || c == '\r');
+ // isspace takes 'int' but documents that the value must be representable
+ // by 'unsigned char', or EOF. Cast to 'unsigned char' to avoid sign
+ // extension while casting to 'int'.
+ return (isspace(static_cast<int>(static_cast<unsigned char>(c))) ||
+ c == '\n' || c == '\r');
}
void cmExecuteProcessCommandFixText(std::vector<char>& output,