From 02d672540ef6d3cd75c9a6be3f4d269f4d24a017 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Thu, 24 Jun 2010 21:36:05 +0000 Subject: [PATCH] Fix possible crash when using alternative speed limits --- Changelog | 1 + src/bittorrent.cpp | 16 ++++++++++++++-- src/preferences.h | 10 ++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Changelog b/Changelog index 7a37ff824..5cd83f138 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,6 @@ * Unreleased - Christophe Dumez - v2.2.11 - BUGFIX: Fix parsing of program arguments with spaces + - BUGFIX: Fix possible crashing when using alternative speed limits (#598272) * Wed Jun 23 2010 - Christophe Dumez - v2.2.10 - BUGFIX: Fix Web UI in qBittorrent nox version diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index e938d1974..ca872eff6 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -637,8 +637,20 @@ void Bittorrent::useAlternativeSpeedsLimit(bool alternative) { s->set_download_rate_limit(Preferences::getAltGlobalDownloadLimit()*1024); s->set_upload_rate_limit(Preferences::getAltGlobalUploadLimit()*1024); } else { - s->set_download_rate_limit(Preferences::getGlobalDownloadLimit()*1024); - s->set_upload_rate_limit(Preferences::getGlobalUploadLimit()*1024); + int down_limit = Preferences::getGlobalDownloadLimit(); + if(down_limit <= 0) { + down_limit = -1; + } else { + down_limit *= 1024; + } + s->set_download_rate_limit(down_limit); + int up_limit = Preferences::getGlobalUploadLimit(); + if(up_limit <= 0) { + up_limit = -1; + } else { + up_limit *= 1024; + } + s->set_upload_rate_limit(up_limit); } emit alternativeSpeedsModeChanged(alternative); } diff --git a/src/preferences.h b/src/preferences.h index 0d3fcfd2f..7f1f041ca 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -310,7 +310,10 @@ public: static int getAltGlobalDownloadLimit() { QSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Connection/GlobalDLLimitAlt"), 10).toInt(); + int ret = settings.value(QString::fromUtf8("Preferences/Connection/GlobalDLLimitAlt"), 10).toInt(); + if(ret <= 0) + ret = 10; + return ret; } static void setAltGlobalDownloadLimit(int limit) { @@ -321,7 +324,10 @@ public: static int getAltGlobalUploadLimit() { QSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/Connection/GlobalUPLimitAlt"), 10).toInt(); + int ret = settings.value(QString::fromUtf8("Preferences/Connection/GlobalUPLimitAlt"), 10).toInt(); + if(ret <= 0) + ret = 10; + return ret; } static void setAltGlobalUploadLimit(int limit) {