1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-30 16:34:16 +00:00

Merge pull request #6358 from Chocobo1/coverity

Fix issues on coverity
This commit is contained in:
sledgehammer999 2017-02-08 15:34:45 +02:00 committed by GitHub
commit 73f762250c
5 changed files with 26 additions and 9 deletions

View File

@ -440,21 +440,27 @@ QString Utils::Misc::userFriendlyDuration(qlonglong seconds)
{ {
if ((seconds < 0) || (seconds >= MAX_ETA)) if ((seconds < 0) || (seconds >= MAX_ETA))
return QString::fromUtf8(C_INFINITY); return QString::fromUtf8(C_INFINITY);
if (seconds == 0) if (seconds == 0)
return "0"; return "0";
if (seconds < 60) if (seconds < 60)
return QCoreApplication::translate("misc", "< 1m", "< 1 minute"); return QCoreApplication::translate("misc", "< 1m", "< 1 minute");
int minutes = seconds / 60;
qlonglong minutes = seconds / 60;
if (minutes < 60) if (minutes < 60)
return QCoreApplication::translate("misc", "%1m", "e.g: 10minutes").arg(QString::number(minutes)); return QCoreApplication::translate("misc", "%1m", "e.g: 10minutes").arg(QString::number(minutes));
int hours = minutes / 60;
minutes = minutes - hours * 60; qlonglong hours = minutes / 60;
minutes -= hours * 60;
if (hours < 24) if (hours < 24)
return QCoreApplication::translate("misc", "%1h %2m", "e.g: 3hours 5minutes").arg(QString::number(hours)).arg(QString::number(minutes)); return QCoreApplication::translate("misc", "%1h %2m", "e.g: 3hours 5minutes").arg(QString::number(hours)).arg(QString::number(minutes));
int days = hours / 24;
hours = hours - days * 24; qlonglong days = hours / 24;
hours -= days * 24;
if (days < 100) if (days < 100)
return QCoreApplication::translate("misc", "%1d %2h", "e.g: 2days 10hours").arg(QString::number(days)).arg(QString::number(hours)); return QCoreApplication::translate("misc", "%1d %2h", "e.g: 2days 10hours").arg(QString::number(days)).arg(QString::number(hours));
return QString::fromUtf8(C_INFINITY); return QString::fromUtf8(C_INFINITY);
} }

View File

@ -177,8 +177,12 @@ QString Utils::String::fromStdString(const std::string &str)
std::string Utils::String::toStdString(const QString &str) std::string Utils::String::toStdString(const QString &str)
{ {
#ifdef QBT_USES_QT5
return str.toStdString();
#else
QByteArray utf8 = str.toUtf8(); QByteArray utf8 = str.toUtf8();
return std::string(utf8.constData(), utf8.length()); return std::string(utf8.constData(), utf8.length());
#endif
} }
// to send numbers instead of strings with suffixes // to send numbers instead of strings with suffixes

View File

@ -845,16 +845,21 @@ void OptionsDialog::loadOptions()
case ProxyType::SOCKS4: case ProxyType::SOCKS4:
m_ui->comboProxyType->setCurrentIndex(1); m_ui->comboProxyType->setCurrentIndex(1);
break; break;
case ProxyType::SOCKS5_PW: case ProxyType::SOCKS5_PW:
useProxyAuth = true; useProxyAuth = true;
// fallthrough
case ProxyType::SOCKS5: case ProxyType::SOCKS5:
m_ui->comboProxyType->setCurrentIndex(2); m_ui->comboProxyType->setCurrentIndex(2);
break; break;
case ProxyType::HTTP_PW: case ProxyType::HTTP_PW:
useProxyAuth = true; useProxyAuth = true;
// fallthrough
case ProxyType::HTTP: case ProxyType::HTTP:
m_ui->comboProxyType->setCurrentIndex(3); m_ui->comboProxyType->setCurrentIndex(3);
break; break;
default: default:
m_ui->comboProxyType->setCurrentIndex(0); m_ui->comboProxyType->setCurrentIndex(0);
} }

View File

@ -37,6 +37,7 @@ SpeedPlotView::SpeedPlotView(QWidget *parent)
, m_data5Min(MIN5_BUF_SIZE) , m_data5Min(MIN5_BUF_SIZE)
, m_data30Min(MIN30_BUF_SIZE) , m_data30Min(MIN30_BUF_SIZE)
, m_data6Hour(HOUR6_BUF_SIZE) , m_data6Hour(HOUR6_BUF_SIZE)
, m_period(MIN5)
, m_viewablePointsCount(MIN5_SEC) , m_viewablePointsCount(MIN5_SEC)
, m_counter30Min(-1) , m_counter30Min(-1)
, m_counter6Hour(-1) , m_counter6Hour(-1)

View File

@ -288,17 +288,18 @@ void TorrentContentModel::clear()
void TorrentContentModel::setupModelData(const BitTorrent::TorrentInfo &info) void TorrentContentModel::setupModelData(const BitTorrent::TorrentInfo &info)
{ {
qDebug("setup model data called"); qDebug("setup model data called");
if (info.filesCount() <= 0) const int filesCount = info.filesCount();
if (filesCount <= 0)
return; return;
emit layoutAboutToBeChanged(); emit layoutAboutToBeChanged();
// Initialize files_index array // Initialize files_index array
qDebug("Torrent contains %d files", info.filesCount()); qDebug("Torrent contains %d files", filesCount);
m_filesIndex.reserve(info.filesCount()); m_filesIndex.reserve(filesCount);
TorrentContentModelFolder* currentParent; TorrentContentModelFolder* currentParent;
// Iterate over files // Iterate over files
for (int i = 0; i < info.filesCount(); ++i) { for (int i = 0; i < filesCount; ++i) {
currentParent = m_rootItem; currentParent = m_rootItem;
QString path = Utils::Fs::fromNativePath(info.filePath(i)); QString path = Utils::Fs::fromNativePath(info.filePath(i));
// Iterate of parts of the path to create necessary folders // Iterate of parts of the path to create necessary folders