Fix most of critical issues reported by Sonar (GTK client) (#2309)

* (C++) Macros should not be used to define constants

* (C++) Memory should not be managed manually

* (C++) "void*" should not be used in typedefs, member variables, function parameters or return type

* (C++) When the "Rule-of-Zero" is not applicable, the "Rule-of-Five" should be followed

* (C++) "switch" statements should have "default" clauses

* (C++) "explicit" should be used on single-parameter constructors and conversiosn operators

* (C++) Non-const global variables should not be used
This commit is contained in:
Mike Gelfand
2021-12-14 11:43:27 +03:00
committed by GitHub
parent 7015f48798
commit 3e072f9bd4
82 changed files with 459 additions and 287 deletions

View File

@@ -36,6 +36,8 @@ public:
Impl(PrefsDialog& dialog, Glib::RefPtr<Session> const& core);
~Impl();
TR_DISABLE_COPY_MOVE(Impl)
private:
Gtk::Widget* speedPage();
Gtk::Widget* downloadingPage();
@@ -92,12 +94,12 @@ Gtk::CheckButton* new_check_button(Glib::ustring const& mnemonic, tr_quark const
return w;
}
#define IDLE_DATA "idle-data"
auto const IdleDataKey = Glib::Quark("idle-data");
bool spun_cb_idle(Gtk::SpinButton* spin, tr_quark const key, Glib::RefPtr<Session> const& core, bool isDouble)
{
bool keep_waiting = true;
auto* last_change = static_cast<Glib::Timer*>(spin->get_data(IDLE_DATA));
auto* last_change = static_cast<Glib::Timer*>(spin->get_data(IdleDataKey));
/* has the user stopped making changes? */
if (last_change->elapsed() > 0.33)
@@ -115,7 +117,7 @@ bool spun_cb_idle(Gtk::SpinButton* spin, tr_quark const key, Glib::RefPtr<Sessio
}
/* cleanup */
spin->set_data(IDLE_DATA, nullptr);
spin->set_data(IdleDataKey, nullptr);
keep_waiting = false;
spin->unreference();
}
@@ -127,12 +129,12 @@ void spun_cb(Gtk::SpinButton* w, tr_quark const key, Glib::RefPtr<Session> const
{
/* user may be spinning through many values, so let's hold off
for a moment to keep from flooding the core with changes */
auto* last_change = static_cast<Glib::Timer*>(w->get_data(IDLE_DATA));
auto* last_change = static_cast<Glib::Timer*>(w->get_data(IdleDataKey));
if (last_change == nullptr)
{
last_change = new Glib::Timer();
w->set_data(IDLE_DATA, last_change, [](void* p) { delete static_cast<Glib::Timer*>(p); });
w->set_data(IdleDataKey, last_change, [](gpointer p) { delete static_cast<Glib::Timer*>(p); });
w->reference();
Glib::signal_timeout().connect_seconds([w, key, core, isDouble]() { return spun_cb_idle(w, key, core, isDouble); }, 1);
}
@@ -363,8 +365,11 @@ namespace
struct blocklist_data
{
blocklist_data() = default;
~blocklist_data();
TR_DISABLE_COPY_MOVE(blocklist_data)
sigc::connection updateBlocklistTag;
Gtk::Button* updateBlocklistButton = nullptr;
std::unique_ptr<Gtk::MessageDialog> updateBlocklistDialog;
@@ -918,8 +923,11 @@ namespace
struct network_page_data
{
network_page_data() = default;
~network_page_data();
TR_DISABLE_COPY_MOVE(network_page_data)
Glib::RefPtr<Session> core;
Gtk::Label* portLabel = nullptr;
Gtk::Button* portButton = nullptr;