diff options
Diffstat (limited to 'Source/cmFileCommand.cxx')
-rw-r--r-- | Source/cmFileCommand.cxx | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index c3ae22893..da2f15fdf 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -197,15 +197,15 @@ 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()); + 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 @@ -215,28 +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]; - sprintf(hex, "%.2x", c & 0xff); + 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--; - } - if (sizeLimit < 0) { - sizeLimit = 0; - } + sizeLimit = sizeLimit - line.size(); + if (has_newline && sizeLimit > 0) { + sizeLimit--; } output += line; if (has_newline) { @@ -1632,8 +1625,9 @@ size_t cmFileCommandCurlDebugCallback(CURL*, curl_infotype type, char* chPtr, case CURLINFO_SSL_DATA_IN: case CURLINFO_SSL_DATA_OUT: { char buf[128]; - int n = sprintf(buf, "[%" KWIML_INT_PRIu64 " bytes data]\n", - static_cast<KWIML_INT_uint64_t>(size)); + int n = + snprintf(buf, sizeof(buf), "[%" KWIML_INT_PRIu64 " bytes data]\n", + static_cast<KWIML_INT_uint64_t>(size)); if (n > 0) { cm::append(vec, buf, buf + n); } |