diff options
author | Brad King <brad.king@kitware.com> | 2022-01-12 14:43:00 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2022-01-12 14:43:09 (GMT) |
commit | 34d16d9e56541dad3b9aa2fc45e271cbb08b3097 (patch) | |
tree | 22976734384988cdaeaaaaf3e3ab5186f1799ce8 | |
parent | e804e3ef597e806eaa83d692f3445d6615afc0d5 (diff) | |
parent | 0d37dae5f9f5e143b98bb1766b26fb361fc3edcb (diff) | |
download | CMake-34d16d9e56541dad3b9aa2fc45e271cbb08b3097.zip CMake-34d16d9e56541dad3b9aa2fc45e271cbb08b3097.tar.gz CMake-34d16d9e56541dad3b9aa2fc45e271cbb08b3097.tar.bz2 |
Merge topic 'update-kwsys'
0d37dae5f9 cmFileCommand: Update for new signature of GetLineFromStream
f52dac56a0 Merge branch 'upstream-KWSys' into update-kwsys
6e8a2de4cb KWSys 2022-01-11 (15b0b0c4)
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !6852
-rw-r--r-- | Source/cmFileCommand.cxx | 10 | ||||
-rw-r--r-- | Source/kwsys/SystemInformation.cxx | 7 | ||||
-rw-r--r-- | Source/kwsys/SystemTools.cxx | 8 | ||||
-rw-r--r-- | Source/kwsys/SystemTools.hxx.in | 6 | ||||
-rw-r--r-- | Source/kwsys/testSystemTools.cxx | 21 |
5 files changed, 27 insertions, 25 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 338f3c9..2cce400 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -197,9 +197,10 @@ bool HandleReadCommand(std::vector<std::string> const& args, } // is there a limit? - long sizeLimit = -1; + std::string::size_type sizeLimit = std::string::npos; if (!arguments.Limit.empty()) { - sizeLimit = atoi(arguments.Limit.c_str()); + sizeLimit = + static_cast<std::string::size_type>(atoi(arguments.Limit.c_str())); } // is there an offset? @@ -231,12 +232,9 @@ bool HandleReadCommand(std::vector<std::string> const& args, cmSystemTools::GetLineFromStream(file, line, &has_newline, sizeLimit)) { if (sizeLimit > 0) { sizeLimit = sizeLimit - static_cast<long>(line.size()); - if (has_newline) { + if (has_newline && sizeLimit > 0) { sizeLimit--; } - if (sizeLimit < 0) { - sizeLimit = 0; - } } output += line; if (has_newline) { diff --git a/Source/kwsys/SystemInformation.cxx b/Source/kwsys/SystemInformation.cxx index ecb9bf3..dcbf367 100644 --- a/Source/kwsys/SystemInformation.cxx +++ b/Source/kwsys/SystemInformation.cxx @@ -1265,11 +1265,10 @@ public: } private: - void* GetRealAddress() const + size_t GetRealAddress() const { - return reinterpret_cast<void*>( - static_cast<char*>(this->Address) - - static_cast<char*>(this->BinaryBaseAddress)); + return static_cast<size_t>(static_cast<char*>(this->Address) - + static_cast<char*>(this->BinaryBaseAddress)); } std::string GetFileName(const std::string& path) const; diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 6a8520fe..c339fd5 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -4250,9 +4250,9 @@ std::string SystemTools::MakeCidentifier(const std::string& s) // Convenience function around std::getline which removes a trailing carriage // return and can truncate the buffer as needed. Returns true // if any data were read before the end-of-file was reached. -bool SystemTools::GetLineFromStream(std::istream& is, std::string& line, - bool* has_newline /* = 0 */, - long sizeLimit /* = -1 */) +bool SystemTools::GetLineFromStream( + std::istream& is, std::string& line, bool* has_newline /* = 0 */, + std::string::size_type sizeLimit /* = std::string::npos */) { // Start with an empty line. line = ""; @@ -4277,7 +4277,7 @@ bool SystemTools::GetLineFromStream(std::istream& is, std::string& line, } // if we read too much then truncate the buffer - if (sizeLimit >= 0 && line.size() >= static_cast<size_t>(sizeLimit)) { + if (sizeLimit != std::string::npos && line.size() > sizeLimit) { line.resize(sizeLimit); } } diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in index dd0cb3b..6684695 100644 --- a/Source/kwsys/SystemTools.hxx.in +++ b/Source/kwsys/SystemTools.hxx.in @@ -523,9 +523,9 @@ public: * end-of-file was reached. If the has_newline argument is specified, it will * be true when the line read had a newline character. */ - static bool GetLineFromStream(std::istream& istr, std::string& line, - bool* has_newline = nullptr, - long sizeLimit = -1); + static bool GetLineFromStream( + std::istream& istr, std::string& line, bool* has_newline = nullptr, + std::string::size_type sizeLimit = std::string::npos); /** * Get the parent directory of the directory or file diff --git a/Source/kwsys/testSystemTools.cxx b/Source/kwsys/testSystemTools.cxx index f96bd71..e88a481 100644 --- a/Source/kwsys/testSystemTools.cxx +++ b/Source/kwsys/testSystemTools.cxx @@ -936,7 +936,8 @@ static bool CheckGetLineFromStream() bool result; file.seekg(0, std::ios::beg); - result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, -1); + result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, + std::string::npos); if (!result || line.size() != 5) { std::cerr << "First line does not have five characters: " << line.size() << std::endl; @@ -944,7 +945,8 @@ static bool CheckGetLineFromStream() } file.seekg(0, std::ios::beg); - result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, -1); + result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, + std::string::npos); if (!result || line.size() != 5) { std::cerr << "First line does not have five characters after rewind: " << line.size() << std::endl; @@ -953,10 +955,10 @@ static bool CheckGetLineFromStream() bool ret = true; - for (size_t size = 1; size <= 5; ++size) { + for (std::string::size_type size = 1; size <= 5; ++size) { file.seekg(0, std::ios::beg); - result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, - static_cast<long>(size)); + result = + kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, size); if (!result || line.size() != size) { std::cerr << "Should have read " << size << " characters but got " << line.size() << std::endl; @@ -999,7 +1001,8 @@ static bool CheckGetLineFromStreamLongLine() bool result; // Read first line. - result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, -1); + result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, + std::string::npos); if (!result || line != firstLine) { std::cerr << "First line does not match, expected " << firstLine.size() << " characters, got " << line.size() << std::endl; @@ -1012,7 +1015,8 @@ static bool CheckGetLineFromStreamLongLine() // Read empty line. has_newline = false; - result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, -1); + result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, + std::string::npos); if (!result || !line.empty()) { std::cerr << "Expected successful read with an empty line, got " << line.size() << " characters" << std::endl; @@ -1025,7 +1029,8 @@ static bool CheckGetLineFromStreamLongLine() // Read second line. has_newline = false; - result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, -1); + result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, + std::string::npos); if (!result || line != secondLine) { std::cerr << "Second line does not match, expected " << secondLine.size() << " characters, got " << line.size() << std::endl; |