Fix invalid narrowing conversion to size_t
This commit is contained in:
parent
b3ed23e18e
commit
823bf3d08d
@ -34,14 +34,14 @@ using std::size_t;
|
|||||||
size_t pzstdMain(const Options& options, ErrorHolder& errorHolder) {
|
size_t pzstdMain(const Options& options, ErrorHolder& errorHolder) {
|
||||||
// Open the input file and attempt to determine its size
|
// Open the input file and attempt to determine its size
|
||||||
FILE* inputFd = stdin;
|
FILE* inputFd = stdin;
|
||||||
size_t inputSize = 0;
|
std::uintmax_t inputSize = 0;
|
||||||
if (options.inputFile != "-") {
|
if (options.inputFile != "-") {
|
||||||
inputFd = std::fopen(options.inputFile.c_str(), "rb");
|
inputFd = std::fopen(options.inputFile.c_str(), "rb");
|
||||||
if (!errorHolder.check(inputFd != nullptr, "Failed to open input file")) {
|
if (!errorHolder.check(inputFd != nullptr, "Failed to open input file")) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
inputSize = static_cast<size_t>(file_size(options.inputFile, ec));
|
inputSize = file_size(options.inputFile, ec);
|
||||||
if (ec) {
|
if (ec) {
|
||||||
inputSize = 0;
|
inputSize = 0;
|
||||||
}
|
}
|
||||||
@ -217,14 +217,17 @@ static void compress(
|
|||||||
* @param numThreads The number of threads available to run compression jobs on
|
* @param numThreads The number of threads available to run compression jobs on
|
||||||
* @param params The zstd parameters to be used for compression
|
* @param params The zstd parameters to be used for compression
|
||||||
*/
|
*/
|
||||||
static size_t
|
static size_t calculateStep(
|
||||||
calculateStep(size_t size, size_t numThreads, const ZSTD_parameters& params) {
|
std::uintmax_t size,
|
||||||
|
size_t numThreads,
|
||||||
|
const ZSTD_parameters ¶ms) {
|
||||||
size_t step = 1ul << (params.cParams.windowLog + 2);
|
size_t step = 1ul << (params.cParams.windowLog + 2);
|
||||||
// If file size is known, see if a smaller step will spread work more evenly
|
// If file size is known, see if a smaller step will spread work more evenly
|
||||||
if (size != 0) {
|
if (size != 0) {
|
||||||
size_t newStep = size / numThreads;
|
const std::uintmax_t newStep = size / std::uintmax_t{numThreads};
|
||||||
if (newStep != 0) {
|
if (newStep != 0 &&
|
||||||
step = std::min(step, newStep);
|
newStep <= std::uintmax_t{std::numeric_limits<size_t>::max()}) {
|
||||||
|
step = std::min(step, size_t{newStep});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return step;
|
return step;
|
||||||
@ -268,7 +271,7 @@ void asyncCompressChunks(
|
|||||||
WorkQueue<std::shared_ptr<BufferWorkQueue>>& chunks,
|
WorkQueue<std::shared_ptr<BufferWorkQueue>>& chunks,
|
||||||
ThreadPool& executor,
|
ThreadPool& executor,
|
||||||
FILE* fd,
|
FILE* fd,
|
||||||
size_t size,
|
std::uintmax_t size,
|
||||||
size_t numThreads,
|
size_t numThreads,
|
||||||
ZSTD_parameters params) {
|
ZSTD_parameters params) {
|
||||||
auto chunksGuard = makeScopeGuard([&] { chunks.finish(); });
|
auto chunksGuard = makeScopeGuard([&] { chunks.finish(); });
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#undef ZSTD_STATIC_LINKING_ONLY
|
#undef ZSTD_STATIC_LINKING_ONLY
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace pzstd {
|
namespace pzstd {
|
||||||
@ -52,7 +53,7 @@ void asyncCompressChunks(
|
|||||||
WorkQueue<std::shared_ptr<BufferWorkQueue>>& chunks,
|
WorkQueue<std::shared_ptr<BufferWorkQueue>>& chunks,
|
||||||
ThreadPool& executor,
|
ThreadPool& executor,
|
||||||
FILE* fd,
|
FILE* fd,
|
||||||
std::size_t size,
|
std::uintmax_t size,
|
||||||
std::size_t numThreads,
|
std::size_t numThreads,
|
||||||
ZSTD_parameters parameters);
|
ZSTD_parameters parameters);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user