size_t pzstdMain(const Options& options, ErrorHolder& errorHolder) {
// Open the input file and attempt to determine its size
FILE* inputFd = stdin;
- size_t inputSize = 0;
+ std::uintmax_t inputSize = 0;
if (options.inputFile != "-") {
inputFd = std::fopen(options.inputFile.c_str(), "rb");
if (!errorHolder.check(inputFd != nullptr, "Failed to open input file")) {
return 0;
}
std::error_code ec;
- inputSize = static_cast<size_t>(file_size(options.inputFile, ec));
+ inputSize = file_size(options.inputFile, ec);
if (ec) {
inputSize = 0;
}
* @param numThreads The number of threads available to run compression jobs on
* @param params The zstd parameters to be used for compression
*/
-static size_t
-calculateStep(size_t size, size_t numThreads, const ZSTD_parameters& params) {
+static size_t calculateStep(
+ std::uintmax_t size,
+ size_t numThreads,
+ const ZSTD_parameters ¶ms) {
size_t step = 1ul << (params.cParams.windowLog + 2);
// If file size is known, see if a smaller step will spread work more evenly
if (size != 0) {
- size_t newStep = size / numThreads;
- if (newStep != 0) {
- step = std::min(step, newStep);
+ const std::uintmax_t newStep = size / std::uintmax_t{numThreads};
+ if (newStep != 0 &&
+ newStep <= std::uintmax_t{std::numeric_limits<size_t>::max()}) {
+ step = std::min(step, size_t{newStep});
}
}
return step;
WorkQueue<std::shared_ptr<BufferWorkQueue>>& chunks,
ThreadPool& executor,
FILE* fd,
- size_t size,
+ std::uintmax_t size,
size_t numThreads,
ZSTD_parameters params) {
auto chunksGuard = makeScopeGuard([&] { chunks.finish(); });