1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-11 07:18:08 +00:00

Make GeoIPDatabase interface safer

PR #17899.
This commit is contained in:
Maksim Derbasov 2022-10-21 08:31:37 +03:00 committed by GitHub
parent 1c2dc79f51
commit 597444c527
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 4 deletions

View File

@ -83,7 +83,6 @@ GeoIPDatabase::GeoIPDatabase(const quint32 size)
GeoIPDatabase *GeoIPDatabase::load(const Path &filename, QString &error)
{
GeoIPDatabase *db = nullptr;
QFile file {filename.data()};
if (file.size() > MAX_FILE_SIZE)
{
@ -97,7 +96,7 @@ GeoIPDatabase *GeoIPDatabase::load(const Path &filename, QString &error)
return nullptr;
}
db = new GeoIPDatabase(file.size());
auto *db = new GeoIPDatabase(file.size());
if (file.read(reinterpret_cast<char *>(db->m_data), db->m_size) != db->m_size)
{
@ -118,14 +117,13 @@ GeoIPDatabase *GeoIPDatabase::load(const Path &filename, QString &error)
GeoIPDatabase *GeoIPDatabase::load(const QByteArray &data, QString &error)
{
GeoIPDatabase *db = nullptr;
if (data.size() > MAX_FILE_SIZE)
{
error = tr("Unsupported database file size.");
return nullptr;
}
db = new GeoIPDatabase(data.size());
auto *db = new GeoIPDatabase(data.size());
memcpy(reinterpret_cast<char *>(db->m_data), data.constData(), db->m_size);

View File

@ -44,6 +44,7 @@ struct DataFieldDescriptor;
class GeoIPDatabase
{
Q_DISABLE_COPY_MOVE(GeoIPDatabase)
Q_DECLARE_TR_FUNCTIONS(GeoIPDatabase)
public: