Browse Source

Perform type conversion properly

Closes #19521.
PR #19525.
adaptive-webui-19844
Chocobo1 1 year ago committed by GitHub
parent
commit
24da51ffa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      src/base/utils/io.cpp

11
src/base/utils/io.cpp

@ -28,6 +28,9 @@ @@ -28,6 +28,9 @@
#include "io.h"
#include <limits>
#include <utility>
#include <libtorrent/bencode.hpp>
#include <libtorrent/entry.hpp>
@ -88,8 +91,14 @@ nonstd::expected<QByteArray, Utils::IO::ReadError> Utils::IO::readFile(const Pat @@ -88,8 +91,14 @@ nonstd::expected<QByteArray, Utils::IO::ReadError> Utils::IO::readFile(const Pat
.arg(file.fileName(), QString::number(fileSize), QString::number(maxSize));
return nonstd::make_unexpected(ReadError {ReadError::ExceedSize, message});
}
if (!std::in_range<qsizetype>(fileSize))
{
const QString message = QCoreApplication::translate("Utils::IO", "File size exceeds data size limit. File: \"%1\". File size: %2. Array limit: %3")
.arg(file.fileName(), QString::number(fileSize), QString::number(std::numeric_limits<qsizetype>::max()));
return nonstd::make_unexpected(ReadError {ReadError::ExceedSize, message});
}
QByteArray ret {fileSize, Qt::Uninitialized};
QByteArray ret {static_cast<qsizetype>(fileSize), Qt::Uninitialized};
const qint64 actualSize = file.read(ret.data(), fileSize);
if (actualSize < 0)

Loading…
Cancel
Save