summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2024-01-18 13:54:13 (GMT)
committerKitware Robot <kwrobot@kitware.com>2024-01-18 13:54:25 (GMT)
commit2debd9dd4ec71c38f07671ba73893f22c7899d27 (patch)
tree20106405c6dbc8bb35ea549887872f1420b2397e /Source
parentf3032be9fcc695bf8857cdb3e6d710d7434dc70d (diff)
parentd9d9326e1438855efd5089f76943ce7b31d1f2ad (diff)
downloadCMake-2debd9dd4ec71c38f07671ba73893f22c7899d27.zip
CMake-2debd9dd4ec71c38f07671ba73893f22c7899d27.tar.gz
CMake-2debd9dd4ec71c38f07671ba73893f22c7899d27.tar.bz2
Merge topic 'isspace'
d9d9326e14 Source: Avoid out-of-range inputs to std::isspace() 14abdc8e2b cmXMLParser: Remove unused IsSpace method Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !9162
Diffstat (limited to 'Source')
-rw-r--r--Source/CTest/cmCTestGIT.cxx9
-rw-r--r--Source/cmCMakeHostSystemInformationCommand.cxx4
-rw-r--r--Source/cmExecuteProcessCommand.cxx7
-rw-r--r--Source/cmMakefile.cxx4
-rw-r--r--Source/cmRST.cxx5
-rw-r--r--Source/cmStringAlgorithms.h5
-rw-r--r--Source/cmStringCommand.cxx3
-rw-r--r--Source/cmSystemTools.cxx4
-rw-r--r--Source/cmXMLParser.cxx6
-rw-r--r--Source/cmXMLParser.h4
10 files changed, 18 insertions, 33 deletions
diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx
index 984c837..99c5a2b 100644
--- a/Source/CTest/cmCTestGIT.cxx
+++ b/Source/CTest/cmCTestGIT.cxx
@@ -2,7 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCTestGIT.h"
-#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <ctime>
@@ -414,14 +413,14 @@ protected:
const char* ConsumeSpace(const char* c)
{
- while (*c && isspace(*c)) {
+ while (*c && cmIsSpace(*c)) {
++c;
}
return c;
}
const char* ConsumeField(const char* c)
{
- while (*c && !isspace(*c)) {
+ while (*c && !cmIsSpace(*c)) {
++c;
}
return c;
@@ -481,7 +480,7 @@ private:
{
// Person Name <person@domain.com> 1234567890 +0000
const char* c = str;
- while (*c && isspace(*c)) {
+ while (*c && cmIsSpace(*c)) {
++c;
}
@@ -490,7 +489,7 @@ private:
++c;
}
const char* name_last = c;
- while (name_last != name_first && isspace(*(name_last - 1))) {
+ while (name_last != name_first && cmIsSpace(*(name_last - 1))) {
--name_last;
}
person.Name.assign(name_first, name_last - name_first);
diff --git a/Source/cmCMakeHostSystemInformationCommand.cxx b/Source/cmCMakeHostSystemInformationCommand.cxx
index 699e23b..e4160a1 100644
--- a/Source/cmCMakeHostSystemInformationCommand.cxx
+++ b/Source/cmCMakeHostSystemInformationCommand.cxx
@@ -178,7 +178,7 @@ cm::optional<std::pair<std::string, std::string>> ParseOSReleaseLine(
if (std::isalpha(ch) || ch == '_') {
key += ch;
state = PARSE_KEY;
- } else if (!std::isspace(ch)) {
+ } else if (!cmIsSpace(ch)) {
state = IGNORE_REST;
}
break;
@@ -238,7 +238,7 @@ cm::optional<std::pair<std::string, std::string>> ParseOSReleaseLine(
break;
case PARSE_VALUE:
- if (ch == '#' || std::isspace(ch)) {
+ if (ch == '#' || cmIsSpace(ch)) {
state = IGNORE_REST;
} else {
value += ch;
diff --git a/Source/cmExecuteProcessCommand.cxx b/Source/cmExecuteProcessCommand.cxx
index 483a601..da6def9 100644
--- a/Source/cmExecuteProcessCommand.cxx
+++ b/Source/cmExecuteProcessCommand.cxx
@@ -2,7 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmExecuteProcessCommand.h"
-#include <cctype> /* isspace */
#include <cstdint>
#include <cstdio>
#include <iostream>
@@ -35,11 +34,7 @@
namespace {
bool cmExecuteProcessCommandIsWhitespace(char c)
{
- // 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');
+ return (cmIsSpace(c) || c == '\n' || c == '\r');
}
void cmExecuteProcessCommandFixText(std::vector<char>& output,
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 6fb7734..2687afa 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -1438,8 +1438,8 @@ static void s_RemoveDefineFlag(std::string const& flag, std::string& dflags)
for (std::string::size_type lpos = dflags.find(flag, 0);
lpos != std::string::npos; lpos = dflags.find(flag, lpos)) {
std::string::size_type rpos = lpos + len;
- if ((lpos <= 0 || isspace(dflags[lpos - 1])) &&
- (rpos >= dflags.size() || isspace(dflags[rpos]))) {
+ if ((lpos <= 0 || cmIsSpace(dflags[lpos - 1])) &&
+ (rpos >= dflags.size() || cmIsSpace(dflags[rpos]))) {
dflags.erase(lpos, len);
} else {
++lpos;
diff --git a/Source/cmRST.cxx b/Source/cmRST.cxx
index f48330d..3934a29 100644
--- a/Source/cmRST.cxx
+++ b/Source/cmRST.cxx
@@ -3,7 +3,6 @@
#include "cmRST.h"
#include <algorithm>
-#include <cctype>
#include <cstddef>
#include <iterator>
#include <utility>
@@ -159,7 +158,7 @@ void cmRST::ProcessLine(std::string const& line)
// A line starting in .. is an explicit markup start.
if (line == ".." ||
(line.size() >= 3 && line[0] == '.' && line[1] == '.' &&
- isspace(line[2]))) {
+ cmIsSpace(line[2]))) {
this->Reset();
this->MarkupType =
(line.find_first_not_of(" \t", 2) == std::string::npos ? Markup::Empty
@@ -219,7 +218,7 @@ void cmRST::ProcessLine(std::string const& line)
}
// Indented lines following an explicit markup start are explicit markup.
else if (this->MarkupType != Markup::None &&
- (line.empty() || isspace(line[0]))) {
+ (line.empty() || cmIsSpace(line[0]))) {
this->MarkupType = Markup::Normal;
// Record markup lines if the start line was recorded.
if (!this->MarkupLines.empty()) {
diff --git a/Source/cmStringAlgorithms.h b/Source/cmStringAlgorithms.h
index 4a9840b..55a1e46 100644
--- a/Source/cmStringAlgorithms.h
+++ b/Source/cmStringAlgorithms.h
@@ -44,7 +44,10 @@ private:
/** Returns true if the character @a ch is a whitespace character. **/
inline bool cmIsSpace(char ch)
{
- return ((ch & 0x80) == 0) && std::isspace(ch);
+ // isspace takes 'int' but documents that the value must be representable
+ // by 'unsigned char', or be EOF. Cast to 'unsigned char' to avoid sign
+ // extension while converting to 'int'.
+ return std::isspace(static_cast<unsigned char>(ch));
}
/** Returns a string that has whitespace removed from the start and the end. */
diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx
index 5a64588..ab87f34 100644
--- a/Source/cmStringCommand.cxx
+++ b/Source/cmStringCommand.cxx
@@ -6,7 +6,6 @@
#include "cmStringCommand.h"
#include <algorithm>
-#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <limits>
@@ -660,7 +659,7 @@ bool HandleStripCommand(std::vector<std::string> const& args,
const char* ptr = stringValue.c_str();
size_t cc;
for (cc = 0; cc < inStringLength; ++cc) {
- if (!isspace(*ptr)) {
+ if (!cmIsSpace(*ptr)) {
if (startPos > inStringLength) {
startPos = cc;
}
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 1b3dbe2..fca8186 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -486,7 +486,7 @@ bool cmSystemTools::SplitProgramFromArgs(std::string const& command,
const char* c = command.c_str();
// Skip leading whitespace.
- while (isspace(static_cast<unsigned char>(*c))) {
+ while (cmIsSpace(*c)) {
++c;
}
@@ -516,7 +516,7 @@ bool cmSystemTools::SplitProgramFromArgs(std::string const& command,
in_double = true;
} else if (*c == '\'') {
in_single = true;
- } else if (isspace(static_cast<unsigned char>(*c))) {
+ } else if (cmIsSpace(*c)) {
break;
} else {
program += *c;
diff --git a/Source/cmXMLParser.cxx b/Source/cmXMLParser.cxx
index 24da8c6..f4433e3 100644
--- a/Source/cmXMLParser.cxx
+++ b/Source/cmXMLParser.cxx
@@ -2,7 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmXMLParser.h"
-#include <cctype>
#include <cstring>
#include <iostream>
#include <sstream>
@@ -143,11 +142,6 @@ void cmXMLParser::CharacterDataHandler(const char* /*inData*/,
{
}
-int cmXMLParser::IsSpace(char c)
-{
- return isspace(c);
-}
-
const char* cmXMLParser::FindAttribute(const char** atts,
const char* attribute)
{
diff --git a/Source/cmXMLParser.h b/Source/cmXMLParser.h
index 176252d..d35e44f 100644
--- a/Source/cmXMLParser.h
+++ b/Source/cmXMLParser.h
@@ -89,10 +89,6 @@ protected:
/** Called by ReportXmlParseError with basic error info. */
virtual void ReportError(int line, int column, const char* msg);
- //! Utility for convenience of subclasses. Wraps isspace C library
- // routine.
- static int IsSpace(char c);
-
//! Send the given buffer to the XML parser.
virtual int ParseBuffer(const char* buffer, std::string::size_type length);