فهرست منبع

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
leha-bot 1 سال پیش
والد
کامیت
5e8c176e2a
1فایلهای تغییر یافته به همراه5 افزوده شده و 1 حذف شده
  1. 5 1
      Source/cmExecuteProcessCommand.cxx

+ 5 - 1
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,