diff options
author | Brad King <brad.king@kitware.com> | 2022-01-14 13:45:58 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2022-01-14 13:46:07 (GMT) |
commit | a0e78cc30c9c3ab71ef6030cc30e4be51468ffb4 (patch) | |
tree | e49c26b6831fd4f139a49e6b3052f0940bc78546 | |
parent | 84a910d86d68e340a88d121cd764413c9a7249c8 (diff) | |
parent | fd0c285b12f4235ba62e13489a6a09e487825cf6 (diff) | |
download | CMake-a0e78cc30c9c3ab71ef6030cc30e4be51468ffb4.zip CMake-a0e78cc30c9c3ab71ef6030cc30e4be51468ffb4.tar.gz CMake-a0e78cc30c9c3ab71ef6030cc30e4be51468ffb4.tar.bz2 |
Merge topic 'fix_file_offset'
fd0c285b12 file: Fix types of the OFFSET and LIMIT arguments
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !6839
-rw-r--r-- | Source/cmFileCommand.cxx | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index d9fb608..da2f15f 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -199,14 +199,13 @@ bool HandleReadCommand(std::vector<std::string> const& args, // is there a limit? std::string::size_type sizeLimit = std::string::npos; if (!arguments.Limit.empty()) { - sizeLimit = - static_cast<std::string::size_type>(atoi(arguments.Limit.c_str())); + std::istringstream(arguments.Limit) >> sizeLimit; } // is there an offset? - long offset = 0; + cmsys::ifstream::off_type offset = 0; if (!arguments.Offset.empty()) { - offset = atoi(arguments.Offset.c_str()); + std::istringstream(arguments.Offset) >> offset; } file.seekg(offset, std::ios::beg); // explicit ios::beg for IBM VisualAge 6 @@ -216,25 +215,21 @@ bool HandleReadCommand(std::vector<std::string> const& args, if (arguments.Hex) { // Convert part of the file into hex code char c; - while ((sizeLimit != 0) && (file.get(c))) { + while ((sizeLimit > 0) && (file.get(c))) { char hex[4]; snprintf(hex, sizeof(hex), "%.2x", c & 0xff); output += hex; - if (sizeLimit > 0) { - sizeLimit--; - } + sizeLimit--; } } else { std::string line; bool has_newline = false; while ( - sizeLimit != 0 && + sizeLimit > 0 && cmSystemTools::GetLineFromStream(file, line, &has_newline, sizeLimit)) { - if (sizeLimit > 0) { - sizeLimit = sizeLimit - static_cast<long>(line.size()); - if (has_newline && sizeLimit > 0) { - sizeLimit--; - } + sizeLimit = sizeLimit - line.size(); + if (has_newline && sizeLimit > 0) { + sizeLimit--; } output += line; if (has_newline) { |