[pan: 6/22] deal with a bunch of issues detected by cppcheck




commit 18f92b133d5d831ed7acca2944516b3fda80a33e
Author: Thomas Tanner <thosrtanner googlemail com>
Date:   Sun Jul 3 19:51:04 2022 +0100

    deal with a bunch of issues detected by cppcheck

 pan/data-impl/data-impl.h    | 14 ++++-----
 pan/data/parts.cc            | 52 ++++++++++++++++++-------------
 pan/general/e-util.cc        | 74 +++++++++++---------------------------------
 pan/general/e-util.h         |  7 +++--
 pan/general/line-reader.h    |  9 ++++--
 pan/general/text-match.cc    | 13 +++++---
 pan/gui/body-pane.cc         | 40 +++++++++++++-----------
 pan/gui/dl-headers-ui.cc     | 25 ++++++++++++---
 pan/gui/gui.h                | 12 ++++---
 pan/gui/log-ui.cc            | 13 +++++---
 pan/gui/pan.cc               |  4 +--
 pan/gui/post-ui.cc           |  1 +
 pan/gui/prefs.cc             | 10 +++---
 pan/gui/server-ui.cc         | 47 ++++++++++++++++++++++------
 pan/gui/task-pane.h          |  4 +--
 pan/tasks/task-article.h     |  7 ++++-
 pan/tasks/task.h             | 10 +++++-
 pan/usenet-utils/gpg.h       | 17 +++++++---
 pan/usenet-utils/ssl-utils.h | 16 ++++++++--
 19 files changed, 221 insertions(+), 154 deletions(-)
---
diff --git a/pan/data-impl/data-impl.h b/pan/data-impl/data-impl.h
index f1148cc..63a48db 100644
--- a/pan/data-impl/data-impl.h
+++ b/pan/data-impl/data-impl.h
@@ -64,7 +64,7 @@ namespace pan
    *
    * @ingroup data_impl
    */
-  class DataImpl:
+  class DataImpl final:
     public Data,
     public TaskArchive,
     public ProfilesImpl
@@ -78,7 +78,7 @@ namespace pan
       /* The ProfilesImpl will own and destruct the DataIO object */
       DataImpl (const StringView& cache_ext, Prefs& prefs, bool unit_test=false, int cache_megs=10, DataIO * 
source=new DataIO());
       virtual ~DataImpl ();
-      virtual void save_state ();
+      void save_state() override final;
 
     public:
       virtual ArticleCache& get_cache () { return _cache; }
@@ -470,7 +470,7 @@ namespace pan
 
     private:
 
-      class MyTree: public Data::ArticleTree
+      class MyTree final: public Data::ArticleTree
       {
         friend class DataImpl;
 
@@ -488,10 +488,10 @@ namespace pan
           virtual const Article* get_parent (const Quark& mid) const;
           virtual const Article* get_article (const Quark& mid) const;
           virtual size_t size () const;
-          virtual void set_filter (const ShowType      show_type = SHOW_ARTICLES,
-                                   const FilterInfo  * criteria  = 0);
-          virtual void set_rules  (const ShowType      show_type = SHOW_ARTICLES,
-                                   const RulesInfo   * rules  = 0);
+          void set_filter (const ShowType      show_type = SHOW_ARTICLES,
+                           const FilterInfo  * criteria  = 0) final override;
+          void set_rules  (const ShowType      show_type = SHOW_ARTICLES,
+                           const RulesInfo   * rules  = 0) final override;
 
         public:
           void articles_changed (const quarks_t& mids, bool do_refilter);
diff --git a/pan/data/parts.cc b/pan/data/parts.cc
index d83253c..4c5ea33 100644
--- a/pan/data/parts.cc
+++ b/pan/data/parts.cc
@@ -17,17 +17,18 @@
  *
  */
 
+#include "parts.h"
+
 #include <config.h>
 #include <cassert>
 #include <algorithm>
 #include <pan/general/debug.h>
 #include <pan/general/macros.h>
-#include "article.h"
-
-using namespace pan;
+#include <pan/general/string-view.h>
 
 #undef DEBUG
 
+namespace pan {
 /***
 ****
 ***/
@@ -62,7 +63,7 @@ namespace
     uint8_t b, e;
     const char * mid;
     size_t midlen;
-    Packer(): b(0), e(0), mid(0), midlen(0) {}
+    Packer(): b(0), e(0), mid(nullptr), midlen(0) {}
     void pack (char* buf) const {
       *buf++ = b;
       *buf++ = e;
@@ -87,7 +88,7 @@ namespace
     for (; b!=bmax; ++b)
       if (*k++ != *m++)
         break;
-    
+
     const int emax = std::min (shorter-b, (int)UCHAR_MAX);
     k = &key.back();
     m = &mid.back();
@@ -129,7 +130,6 @@ namespace
 /***
 ****
 ***/
-
 Parts :: Parts ():
   n_parts_total (0),
   part_mid_buf_len (0),
@@ -163,15 +163,18 @@ Parts :: Parts (const Parts& that):
 Parts&
 Parts :: operator= (const Parts& that)
 {
-  clear ();
-
-  n_parts_total = that.n_parts_total;
-  part_mid_buf_len = that.part_mid_buf_len;
-  parts.reserve( n_parts_total );
-  parts = that.parts;
-  assert( parts.capacity() == n_parts_total );
-  part_mid_buf = new char [part_mid_buf_len];
-  memcpy (part_mid_buf, that.part_mid_buf, part_mid_buf_len);
+  if (this != &that)
+  {
+    clear ();
+
+    n_parts_total = that.n_parts_total;
+    part_mid_buf_len = that.part_mid_buf_len;
+    parts.reserve( n_parts_total );
+    parts = that.parts;
+    assert( parts.capacity() == n_parts_total );
+    part_mid_buf = new char [part_mid_buf_len];
+    memcpy (part_mid_buf, that.part_mid_buf, part_mid_buf_len);
+  }
 
   return *this;
 }
@@ -188,7 +191,7 @@ Parts :: unpack_message_id (std::string  & setme,
   StringView v;
   v.str = part_mid_buf + part->mid_offset;
   v.len = 2 + strlen (v.str+2);
-  ::unpack_message_id (setme, v, reference_mid);
+  pan::unpack_message_id (setme, v, reference_mid);
 }
 
 bool
@@ -319,12 +322,15 @@ PartBatch :: add_part (number_t            number,
 PartBatch :: Part&
 PartBatch :: Part :: operator= (const PartBatch :: Part& that)
 {
-  number =  that.number;
-  bytes =  that.bytes;
-  len_used = that.len_used;
-  delete [] packed_mid;
-  packed_mid = new char [len_used];
-  memcpy (packed_mid, that.packed_mid, len_used);
+  if (this != &that)
+  {
+    number =  that.number;
+    bytes =  that.bytes;
+    len_used = that.len_used;
+    delete [] packed_mid;
+    packed_mid = new char [len_used];
+    memcpy (packed_mid, that.packed_mid, len_used);
+  }
   return *this;
 }
 
@@ -336,6 +342,7 @@ PartBatch :: Part :: Part (const PartBatch::Part& that):
 {
   memcpy (packed_mid, that.packed_mid, len_used);
 }
+
 PartBatch :: Part :: Part (number_t n, bytes_t b, size_t l):
     number(n),
     bytes(b),
@@ -350,3 +357,4 @@ PartBatch :: sort (void)
   std::sort (parts.begin (), parts.end ());
 }
 
+}
diff --git a/pan/general/e-util.cc b/pan/general/e-util.cc
index b21ca1b..003003b 100644
--- a/pan/general/e-util.cc
+++ b/pan/general/e-util.cc
@@ -1,5 +1,5 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* 
+/*
  * e-util.c
  * Copyright 2000, 2001, Ximian, Inc.
  *
@@ -19,6 +19,8 @@
  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "e-util.h"
+
 #include <config.h>
 #include <iostream>
 #include <cstdlib>
@@ -30,7 +32,10 @@ extern "C" {
 #include <glib.h>
 #include <glib/gi18n.h>
 #include "debug.h"
-#include "e-util.h"
+
+namespace pan {
+
+namespace {
 
 static char *
 e_strdup_strip(const char *string)
@@ -77,44 +82,7 @@ e_strftime(char *s, size_t max, const char *fmt, const struct tm *tm)
 #endif
 }
 
-#if 0
-static size_t 
-e_utf8_strftime(char *s, size_t max, const char *fmt, const struct tm *tm)
-{
-       size_t sz, ret;
-       char *locale_fmt, *buf;
-
-       locale_fmt = g_locale_from_utf8(fmt, -1, NULL, &sz, NULL);
-       if (!locale_fmt)
-               return 0;
-
-       ret = e_strftime(s, max, locale_fmt, tm);
-       if (!ret) {
-               g_free (locale_fmt);
-               return 0;
-       }
-
-       buf = g_locale_to_utf8(s, ret, NULL, &sz, NULL);
-       if (!buf) {
-               g_free (locale_fmt);
-               return 0;
-       }
-
-       if (sz >= max) {
-               char *tmp = buf + max - 1;
-               tmp = g_utf8_find_prev_char(buf, tmp);
-               if (tmp)
-                       sz = tmp - buf;
-               else
-                       sz = 0;
-       }
-       memcpy(s, buf, sz);
-       s[sz] = '\0';
-       g_free(locale_fmt);
-       g_free(buf);
-       return sz;
 }
-#endif
 
 /**
  * Function to do a last minute fixup of the AM/PM stuff if the locale
@@ -161,7 +129,7 @@ EvolutionDateMaker :: e_strftime_fix_am_pm (char *s,
   return ret;
 }
 
-size_t 
+size_t
 EvolutionDateMaker :: e_utf8_strftime_fix_am_pm (char *s,
                                                  size_t max,
                                                  const char *locale_fmt,
@@ -192,10 +160,15 @@ EvolutionDateMaker :: e_utf8_strftime_fix_am_pm (char *s,
 #define localtime_r(a,b) *(b) = *localtime(a)
 #endif
 
-void
-EvolutionDateMaker :: set_current_time (time_t now)
+EvolutionDateMaker :: EvolutionDateMaker (time_t now) :
+    locale_recent(g_locale_from_utf8 (_("%l:%M %p"), -1, NULL, NULL, NULL)),
+    locale_today(g_locale_from_utf8 (_("Today %l:%M %p"), -1, NULL, NULL, NULL)),
+    locale_this_week(g_locale_from_utf8 (_("%a %l:%M %p"), -1, NULL, NULL, NULL)),
+    locale_this_year(g_locale_from_utf8 (_("%b %d %l:%M %p"), -1, NULL, NULL, NULL)),
+    locale_old(g_locale_from_utf8 (_("%b %d %Y"), -1, NULL, NULL, NULL)),
+    now_time(now)
 {
-  now_time = now;
+  // set the current time
   localtime_r (&now_time, &now_tm);
   time_t tmp_time = now_time;
   const size_t secs_in_day = 60 * 60 * 24;
@@ -203,19 +176,6 @@ EvolutionDateMaker :: set_current_time (time_t now)
     tmp_time -= secs_in_day;
     localtime_r (&tmp_time, &last_seven_days[i]);
   }
-}
-
-EvolutionDateMaker :: EvolutionDateMaker (time_t now)
-{
-  // build the locale strings
-  locale_recent = g_locale_from_utf8 (_("%l:%M %p"), -1, NULL, NULL, NULL);
-  locale_today = g_locale_from_utf8 (_("Today %l:%M %p"), -1, NULL, NULL, NULL);
-  locale_this_week = g_locale_from_utf8 (_("%a %l:%M %p"), -1, NULL, NULL, NULL);
-  locale_this_year = g_locale_from_utf8 (_("%b %d %l:%M %p"), -1, NULL, NULL, NULL);
-  locale_old = g_locale_from_utf8 (_("%b %d %Y"), -1, NULL, NULL, NULL);
-
-  // set the current time
-  set_current_time (now);
 
   // test to see if am/pm symbols are defined in this locale
   char buf[10];
@@ -289,3 +249,5 @@ EvolutionDateMaker :: get_date_string (time_t then_time) const
 
   return e_strdup_strip (buf);
 }
+
+}
diff --git a/pan/general/e-util.h b/pan/general/e-util.h
index 4325179..3893f8a 100644
--- a/pan/general/e-util.h
+++ b/pan/general/e-util.h
@@ -1,5 +1,5 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* 
+/*
  * e-util.h
  * Copyright 2000, 2001, Ximian, Inc.
  *
@@ -25,6 +25,8 @@
 #include <stddef.h>
 #include <time.h>
 
+namespace pan {
+
 class EvolutionDateMaker
 {
   private:
@@ -49,8 +51,9 @@ class EvolutionDateMaker
   public:
     EvolutionDateMaker (time_t n=time(0));
     ~EvolutionDateMaker ();
-    void set_current_time (time_t n);
     char* get_date_string (time_t date) const;
 };
 
+}
+
 #endif /* _E_UTIL_H_ */
diff --git a/pan/general/line-reader.h b/pan/general/line-reader.h
index 1018f0e..6237f0f 100644
--- a/pan/general/line-reader.h
+++ b/pan/general/line-reader.h
@@ -12,7 +12,7 @@ namespace pan
   /**
    * Interface for objects that read data line-by-line.
    *
-   * These hold live data when running Pan and test data 
+   * These hold live data when running Pan and test data
    * when we're running unit tests.
    *
    * Maybe this should be replaced with good ol' std::getline(istream).
@@ -31,7 +31,7 @@ namespace pan
    * A LineReader that reads from a local file.
    * @ingroup general
    */
-  class FileLineReader: public LineReader
+  class FileLineReader final: public LineReader
   {
     public:
       FileLineReader (const StringView& filename);
@@ -39,6 +39,9 @@ namespace pan
       virtual bool getline (StringView& setme);
       virtual bool fail () const { return !_fp || ferror(_fp); }
 
+      FileLineReader(FileLineReader const &) = delete;
+      FileLineReader operator=(FileLineReader const &) = delete;
+
     private:
       char * _buf;
       const char * _bufend;
@@ -53,7 +56,7 @@ namespace pan
    *
    * @ingroup general
    */
-  class ScriptedLineReader: public LineReader
+  class ScriptedLineReader final: public LineReader
   {
     public:
       ScriptedLineReader () {}
diff --git a/pan/general/text-match.cc b/pan/general/text-match.cc
index 8486b17..a76d6f5 100644
--- a/pan/general/text-match.cc
+++ b/pan/general/text-match.cc
@@ -165,7 +165,7 @@ class pan::TextMatch::PcreInfo
 
    public:
 
-      PcreInfo (): re(0) { } 
+      PcreInfo (): re(0) { }
 
 
 
@@ -250,7 +250,7 @@ namespace
       const guchar first_lc = tolower(*pat);
       const guchar * t = text;
       const guchar * text_end = text + text_len - pat_len + 1;
-      const guchar * pat_end = pat + pat_len; 
+      const guchar * pat_end = pat + pat_len;
       const guchar * p;
       const guchar * q;
 
@@ -294,7 +294,7 @@ namespace
       const guchar first = *pat;
       const guchar * t = text;
       const guchar * text_end = text + text_len - pat_len + 1;
-      const guchar * pat_end  = pat + pat_len; 
+      const guchar * pat_end  = pat + pat_len;
       const guchar * p;
       const guchar * q;
 
@@ -324,7 +324,7 @@ namespace
 
 /*****
 ******
-******  
+******
 ******
 *****/
 
@@ -383,7 +383,7 @@ TextMatch :: test (const StringView& text_in) const
 
 /*****
 ******
-******  
+******
 ******
 *****/
 
@@ -503,6 +503,9 @@ TextMatch :: TextMatch (const TextMatch& that):
   set (that.state);
 }
 
+//FIXME this is clearly doing something odd, but the solution of deleting the
+//assignment and writing defaulted move constructors/assignments won't work
+//till C++20
 TextMatch&
 TextMatch :: operator= (const TextMatch& that)
 {
diff --git a/pan/gui/body-pane.cc b/pan/gui/body-pane.cc
index 4f03a87..14b8e13 100644
--- a/pan/gui/body-pane.cc
+++ b/pan/gui/body-pane.cc
@@ -17,6 +17,8 @@
  *
  */
 
+#include "body-pane.h"
+
 #include <config.h>
 #include <cctype>
 #include <cmath>
@@ -35,7 +37,6 @@
 #include <pan/usenet-utils/mime-utils.h>
 #include <pan/usenet-utils/url-find.h>
 #include <pan/icons/pan-pixbufs.h>
-#include "body-pane.h"
 #include "pad.h"
 #include "tango-colors.h"
 #include "xface.h"
@@ -51,7 +52,7 @@
 
 #define FACE_SIZE 48
 
-using namespace pan;
+namespace pan {
 
 /***
 ****
@@ -597,11 +598,11 @@ namespace
                               int                      utf8_byte_len)
   {
     const char * str = utf8_line;
-    const char * line_end = utf8_line + utf8_byte_len;
     const char * retval = "quote_0";
 
     if (0<utf8_byte_len && str && *str)
     {
+      const char * line_end = utf8_line + utf8_byte_len;
       int depth = 0;
 
       // walk past leading spaces
@@ -619,12 +620,13 @@ namespace
         str = g_utf8_next_char (str);
       }
 
-      if (!depth)
-        retval = "quote_0";
-      else switch (depth % 3) {
-        case 1: retval = "quote_1"; break;
-        case 2: retval = "quote_2"; break;
-        case 0: retval = "quote_3"; break;
+      if (depth != 0)
+      {
+        switch (depth % 3) {
+          case 1: retval = "quote_1"; break;
+          case 2: retval = "quote_2"; break;
+          case 0: retval = "quote_3"; break;
+        }
       }
     }
 
@@ -1520,6 +1522,7 @@ BodyPane :: copy_url_cb (GtkMenuItem *mi G_GNUC_UNUSED, gpointer pane)
 {
   static_cast<BodyPane*>(pane)->copy_url ();
 }
+
 void
 BodyPane :: copy_url ()
 {
@@ -1527,7 +1530,6 @@ BodyPane :: copy_url ()
                           _hover_url.c_str(), _hover_url.size());
 }
 
-
 void
 BodyPane :: populate_popup_cb (GtkTextView *v, GtkMenu *m, gpointer pane)
 {
@@ -1568,8 +1570,8 @@ namespace
     {
       gtk_menu_popup
       (GTK_MENU(bp->_menu), NULL, NULL, NULL, NULL,
-      (event ? event->button : 0),
-      (event ? event->time : 0));
+      event->button,
+      event->time);
     }
 
     return TRUE;
@@ -2202,12 +2204,12 @@ BodyPane :: on_prefs_string_changed (const StringView& key, const StringView& va
 
 void
 BodyPane :: on_prefs_color_changed (const StringView& key, const GdkColor& color G_GNUC_UNUSED)
-{              
-  if ((key == "text-color-fg")              || (key == "text-color-bg")              || 
-      (key == "body-pane-color-url")        || (key == "body-pane-color-url-bg")     || 
-      (key == "body-pane-color-quote-1")    || (key == "body-pane-color-quote-2")    || 
-      (key == "body-pane-color-quote-3")    || (key == "body-pane-color-quote-1-bg") || 
-      (key == "body-pane-color-quote-2-bg") || (key == "body-pane-color-quote-3-bg") || 
+{
+  if ((key == "text-color-fg")              || (key == "text-color-bg")              ||
+      (key == "body-pane-color-url")        || (key == "body-pane-color-url-bg")     ||
+      (key == "body-pane-color-quote-1")    || (key == "body-pane-color-quote-2")    ||
+      (key == "body-pane-color-quote-3")    || (key == "body-pane-color-quote-1-bg") ||
+      (key == "body-pane-color-quote-2-bg") || (key == "body-pane-color-quote-3-bg") ||
       (key == "body-pane-color-signature")  || (key == "body-pane-color-signature-bg"))
   {
     refresh_colors ();
@@ -2231,3 +2233,5 @@ BodyPane :: set_character_encoding (const char * charset)
 
   refresh ();
 }
+
+}
diff --git a/pan/gui/dl-headers-ui.cc b/pan/gui/dl-headers-ui.cc
index f235c9d..0cb381b 100644
--- a/pan/gui/dl-headers-ui.cc
+++ b/pan/gui/dl-headers-ui.cc
@@ -17,6 +17,8 @@
  *
  */
 
+#include "dl-headers-ui.h"
+
 #include <config.h>
 #include <glib.h>
 #include <glib/gi18n.h>
@@ -24,10 +26,9 @@
 #include <pan/general/macros.h>
 #include <pan/tasks/queue.h>
 #include <pan/tasks/task-xover.h>
-#include "dl-headers-ui.h"
 #include "pad.h"
 
-using namespace pan;
+namespace pan {
 
 namespace
 {
@@ -44,7 +45,20 @@ namespace
     GtkWidget * n_headers_spinbutton;
     GtkWidget * n_days_rb;
     GtkWidget * n_days_spinbutton;
-    State (Data& d, Prefs& p, Queue& q): data(d), prefs(p), queue(q) {}
+
+    State (Data& d, Prefs& p, Queue& q):
+      data(d),
+      prefs(p),
+      queue(q),
+      dialog(nullptr),
+      all_headers_rb(nullptr),
+      new_headers_rb(nullptr),
+      n_headers_rb(nullptr),
+      n_headers_spinbutton(nullptr),
+      n_days_rb(nullptr),
+      n_days_spinbutton(nullptr)
+
+   {}
   };
 
   void delete_state (gpointer state_gpointer)
@@ -94,8 +108,7 @@ namespace
   }
 }
 
-void
-pan :: headers_dialog (Data& data, Prefs& prefs, Queue& queue,
+void headers_dialog (Data& data, Prefs& prefs, Queue& queue,
                        const quarks_t& groups,
                        GtkWindow * parent)
 {
@@ -160,3 +173,5 @@ pan :: headers_dialog (Data& data, Prefs& prefs, Queue& queue,
     gtk_widget_show_all (state->dialog);
   }
 }
+
+}
diff --git a/pan/gui/gui.h b/pan/gui/gui.h
index 2c0717f..46782dc 100644
--- a/pan/gui/gui.h
+++ b/pan/gui/gui.h
@@ -50,7 +50,7 @@ namespace pan
    * The main GUI object for Pan's GTK frontend
    * @ingroup GUI
    */
-  struct GUI:
+  struct GUI final:
     public virtual PanUI,
     public ActionManager,
     public WaitUI,
@@ -68,6 +68,10 @@ namespace pan
 
       GUI (Data& data, Queue&, Prefs&, GroupPrefs&);
       virtual ~GUI ();
+
+      GUI(GUI const &) = delete;
+      GUI &operator=(GUI const &) = delete;
+
       GtkWidget* root () { return _root; }
       typedef std::vector<std::string> strings_t;
 
@@ -176,8 +180,8 @@ namespace pan
       virtual void do_bug_report ();
       virtual void do_tip_jar ();
       virtual void do_about_pan ();
-      virtual void do_work_online (bool);
-      virtual void do_layout (bool);
+      void do_work_online (bool) override final;
+      void do_layout (bool) override final;
       virtual void do_show_toolbar (bool);
       virtual void do_show_group_pane (bool);
       virtual void do_show_header_pane (bool);
@@ -214,7 +218,7 @@ namespace pan
 
     private: // Queue::Listener
       friend class Queue;
-      virtual void on_queue_task_active_changed (Queue&, Task&, bool active);
+      void on_queue_task_active_changed (Queue&, Task&, bool active) override final;
       virtual void on_queue_tasks_added (Queue&, int index UNUSED, int count UNUSED) { }
       virtual void on_queue_task_removed (Queue&, Task&, int pos UNUSED) { }
       virtual void on_queue_task_moved (Queue&, Task&, int new_pos UNUSED, int old_pos UNUSED) { }
diff --git a/pan/gui/log-ui.cc b/pan/gui/log-ui.cc
index 8846e1d..395a201 100644
--- a/pan/gui/log-ui.cc
+++ b/pan/gui/log-ui.cc
@@ -17,6 +17,8 @@
  *
  */
 
+#include "log-ui.h"
+
 #include <config.h>
 #include <ostream>
 #include <fstream>
@@ -26,10 +28,9 @@
 #include <pan/general/log.h>
 #include <pan/general/macros.h>
 #include <pan/general/string-view.h>
-#include "log-ui.h"
 #include "pad.h"
 
-using namespace pan;
+namespace pan {
 
 namespace
 {
@@ -213,7 +214,7 @@ namespace
     gtk_tree_model_get (model, iter, COL_MESSAGE, &log_entry, -1);
     bool bold (log_entry->is_child);
     g_object_set (renderer,
-                  "text", log_entry ? log_entry->message.c_str() : "",
+                  "text", log_entry->message.c_str(),
                   "weight", bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL,
                   NULL);
   }
@@ -222,7 +223,7 @@ namespace
 }
 
 gboolean
-pan :: on_button_pressed (GtkWidget *treeview, GdkEventButton *event, gpointer userdata)
+on_button_pressed (GtkWidget *treeview, GdkEventButton *event, gpointer userdata)
 {
   // single click with the right mouse button?
   if (event->type == GDK_BUTTON_PRESS && event->button == 3)
@@ -251,7 +252,7 @@ pan :: on_button_pressed (GtkWidget *treeview, GdkEventButton *event, gpointer u
 }
 
 GtkWidget*
-pan :: log_dialog_new (Prefs& prefs, GtkWindow* window)
+log_dialog_new (Prefs& prefs, GtkWindow* window)
 {
   GtkWidget * dialog = gtk_dialog_new_with_buttons (_("Pan: Events"),
                                                     window,
@@ -332,3 +333,5 @@ pan :: log_dialog_new (Prefs& prefs, GtkWindow* window)
 
   return dialog;
 }
+
+}
diff --git a/pan/gui/pan.cc b/pan/gui/pan.cc
index 35d2816..51c968b 100644
--- a/pan/gui/pan.cc
+++ b/pan/gui/pan.cc
@@ -617,8 +617,8 @@ namespace
     cerr.ios::rdbuf( t2 );
     err.ios::rdbuf( tmp );
 
-    freopen( "CONOUT$", "w", stdout );
-    freopen( "CONOUT$", "w", stderr );
+    (void)freopen( "CONOUT$", "w", stdout );
+    (void)freopen( "CONOUT$", "w", stderr );
   }
 #else
   void console()
diff --git a/pan/gui/post-ui.cc b/pan/gui/post-ui.cc
index bc274ac..6b467dc 100644
--- a/pan/gui/post-ui.cc
+++ b/pan/gui/post-ui.cc
@@ -1365,6 +1365,7 @@ PostUI :: spawn_editor ()
   const std::string body (get_body ());
 
   if (fwrite (body.c_str(), sizeof(char), body.size(), fp) != body.size()) {
+    fclose(fp);
     Log::add_err_va (_("Error writing article to temporary file: %s"), g_strerror(errno));
     return;
   }
diff --git a/pan/gui/prefs.cc b/pan/gui/prefs.cc
index 7a3e985..546353f 100644
--- a/pan/gui/prefs.cc
+++ b/pan/gui/prefs.cc
@@ -17,6 +17,8 @@
  *
  */
 
+#include "prefs.h"
+
 #include <config.h>
 #include <cstdlib>
 #include <fstream>
@@ -28,13 +30,13 @@
 #include <pan/general/debug.h>
 #include <pan/general/log.h>
 #include <pan/general/macros.h>
-#include "prefs.h"
 #include "group-prefs.h"
 
-using namespace pan;
+namespace pan {
 
 Prefs :: Prefs() :
-  _rules_changed(false)
+  _rules_changed(false),
+  _rules_enabled(false)
 {}
 
 Prefs :: ~Prefs()
@@ -402,4 +404,4 @@ Prefs :: get_color_str_wo_fallback (const StringView& key) const
   return color_to_string (col);
 }
 
-
+}
diff --git a/pan/gui/server-ui.cc b/pan/gui/server-ui.cc
index e76ebf7..d0387e6 100644
--- a/pan/gui/server-ui.cc
+++ b/pan/gui/server-ui.cc
@@ -17,6 +17,8 @@
  *
  */
 
+#include "server-ui.h"
+
 #include <config.h>
 #include <cstdlib>
 #include <cstring>
@@ -31,7 +33,6 @@
 #include <pan/general/quark.h>
 #include <pan/data/data.h>
 #include <pan/usenet-utils/ssl-utils.h>
-#include "server-ui.h"
 #include "pad.h"
 #include "hig.h"
 #include "gtk-compat.h"
@@ -50,7 +51,7 @@
 #endif /* GTK_CHECK_VERSION(3,0,0) */
 #endif
 
-using namespace pan;
+namespace pan {
 
 /************
 *************  EDIT DIALOG
@@ -77,9 +78,26 @@ namespace
     GtkWidget * compression_combo;
     GtkWidget * ssl_combo;
     GtkWidget * always_trust_checkbox;
-    ServerEditDialog (Data& d, Queue& q, Prefs& p): data(d), queue(q), prefs(p) {}
     CompressionType compressiontype;
 
+    ServerEditDialog (Data& d, Queue& q, Prefs& p):
+      data(d),
+      queue(q),
+      prefs(p),
+      dialog(nullptr),
+      address_entry(nullptr),
+      port_spin(nullptr),
+      auth_username_entry(nullptr),
+      auth_password_entry(nullptr),
+      connection_limit_spin(nullptr),
+      expiration_age_combo(nullptr),
+      rank_combo(nullptr),
+      compression_combo(nullptr),
+      ssl_combo(nullptr),
+      always_trust_checkbox(nullptr),
+      compressiontype(HEADER_COMPRESS_NONE)
+    {}
+
   };
 
   void pan_entry_set_text (GtkWidget * w, const StringView& v)
@@ -308,7 +326,7 @@ namespace
 }
 
 std::string
-pan :: import_sec_from_disk_dialog_new (Data& data, Queue& queue, GtkWindow * window)
+import_sec_from_disk_dialog_new (Data& data, Queue& queue, GtkWindow * window)
 {
   std::string prev_path = g_get_home_dir ();
   std::string res;
@@ -345,7 +363,7 @@ namespace
 }
 
 GtkWidget*
-pan :: server_edit_dialog_new (Data& data, Queue& queue, Prefs& prefs, GtkWindow * window, const Quark& 
server)
+server_edit_dialog_new (Data& data, Queue& queue, Prefs& prefs, GtkWindow * window, const Quark& server)
 {
   ServerEditDialog * d (new ServerEditDialog (data, queue, prefs));
 
@@ -563,7 +581,16 @@ namespace
     GtkListStore * servers_store;
     GtkWidget * remove_button;
     GtkWidget * edit_button;
-    ServerListDialog (Data& d, Queue& q, Prefs& p): data(d), queue(q), prefs(p) {}
+    ServerListDialog (Data& d, Queue& q, Prefs& p):
+      data(d),
+      queue(q),
+      prefs(p),
+      server_tree_view(nullptr),
+      dialog(nullptr),
+      servers_store(nullptr),
+      remove_button(nullptr),
+      edit_button(nullptr)
+    {}
   };
 
 
@@ -904,7 +931,7 @@ namespace
 #endif
 
 GtkWidget*
-pan :: server_list_dialog_new (Data& data, Queue& queue, Prefs& prefs, GtkWindow* parent)
+server_list_dialog_new (Data& data, Queue& queue, Prefs& prefs, GtkWindow* parent)
 {
   ServerListDialog * d = new ServerListDialog (data, queue, prefs);
 
@@ -980,7 +1007,7 @@ pan :: server_list_dialog_new (Data& data, Queue& queue, Prefs& prefs, GtkWindow
 
 
 void
-pan :: render_cert_flag (GtkTreeViewColumn * ,
+render_cert_flag (GtkTreeViewColumn * ,
                          GtkCellRenderer   * renderer,
                          GtkTreeModel      * model,
                          GtkTreeIter       * iter,
@@ -993,7 +1020,7 @@ pan :: render_cert_flag (GtkTreeViewColumn * ,
 
 
 GtkWidget*
-pan :: sec_dialog_new (Data& data, Queue& queue, Prefs& prefs, GtkWindow* parent)
+sec_dialog_new (Data& data, Queue& queue, Prefs& prefs, GtkWindow* parent)
 {
 #ifdef HAVE_GNUTLS
   ServerListDialog * d = new ServerListDialog (data, queue, prefs);
@@ -1078,3 +1105,5 @@ pan :: sec_dialog_new (Data& data, Queue& queue, Prefs& prefs, GtkWindow* parent
   return 0;
 #endif
 }
+
+}
diff --git a/pan/gui/task-pane.h b/pan/gui/task-pane.h
index 96884b2..384fea6 100644
--- a/pan/gui/task-pane.h
+++ b/pan/gui/task-pane.h
@@ -34,7 +34,7 @@ namespace pan
    * Dialog for showing and manipulating Tasks in a Queue.
    * @ingroup GUI
    */
-  class TaskPane: private Queue::Listener
+  class TaskPane final: private Queue::Listener
   {
     public:
       TaskPane (Queue&, Prefs&);
@@ -49,7 +49,7 @@ namespace pan
       virtual void on_queue_task_moved (Queue&, Task&, int new_index, int old_index);
       virtual void on_queue_connection_count_changed (Queue&, int count);
       virtual void on_queue_size_changed (Queue&, int active, int total);
-      virtual void on_queue_online_changed (Queue&, bool online);
+      void on_queue_online_changed (Queue&, bool online) override final;
       virtual void on_queue_error (Queue&, const StringView&) { }
 
     private:
diff --git a/pan/tasks/task-article.h b/pan/tasks/task-article.h
index 28c843b..407cb20 100644
--- a/pan/tasks/task-article.h
+++ b/pan/tasks/task-article.h
@@ -135,7 +135,12 @@ namespace pan
         typedef std::vector<char> buf_t;
         buf_t buf;
         int rank;
-        Needed (): nntp(0), rank(1) {}
+        Needed ():
+          bytes(0),
+          nntp(nullptr),
+          rank(1)
+        {}
+
         void reset() {
           buf_t tmp;
           buf.swap (tmp); // deallocates space
diff --git a/pan/tasks/task.h b/pan/tasks/task.h
index e9d009f..70421f8 100644
--- a/pan/tasks/task.h
+++ b/pan/tasks/task.h
@@ -106,7 +106,15 @@ namespace pan
 
             public:
 
-               State(): _health(OK) {}
+               //Note: The _work member used to be uninitialised, so depending
+               //on pretty much anything, it could start in ANY of the states,
+               //or none. For now I'm going to assume it starts in completed
+               //state, but it's possible that if the value isn't immediately
+               //set, the task could be reaped early in Queue::process_task
+               State():
+                _work(COMPLETED), //? guesswork
+                _health(OK)
+               {}
          };
 
       public:
diff --git a/pan/usenet-utils/gpg.h b/pan/usenet-utils/gpg.h
index 39c9945..70a3234 100644
--- a/pan/usenet-utils/gpg.h
+++ b/pan/usenet-utils/gpg.h
@@ -20,12 +20,14 @@
 #ifndef _HAVE_GPGDEFS_H
 #define _HAVE_GPGDEFS_H
 
+#include <config.h>
+
+#ifdef HAVE_GMIME_CRYPTO
+
 #include <gmime/gmime.h>
 #include <map>
 #include <vector>
 
-#ifdef HAVE_GMIME_CRYPTO
-
 namespace pan
 {
 
@@ -99,8 +101,6 @@ namespace pan
       if (result) g_object_unref(result);
     }
 
-    GPGDecErr() : err(NULL), no_sigs(true), type(GPG_DECODE), decrypted(NULL), 
result(g_mime_decrypt_result_new()) {}
-
     void clear()
     {
       if (err) g_error_free(err);
@@ -124,7 +124,14 @@ namespace pan
     GPGEncType type;
     GPGSignersInfo signers;
 
-    GPGEncErr(GPGEncType t) : err(NULL), no_sigs(true), type(t)   {}
+    explicit GPGEncErr(GPGEncType t) :
+      err(NULL),
+      enc_ok(false),
+      sign_ok(false),
+      no_sigs(true),
+      type(t)
+    {}
+
     ~GPGEncErr()
     {
       if (err) g_error_free(err);
diff --git a/pan/usenet-utils/ssl-utils.h b/pan/usenet-utils/ssl-utils.h
index 83b6b95..a4baf0d 100644
--- a/pan/usenet-utils/ssl-utils.h
+++ b/pan/usenet-utils/ssl-utils.h
@@ -73,18 +73,24 @@ namespace pan
   {
     std::map<Quark, Quark> tags;
     std::string iss, sub;
-    char buf[2048];
     char * dn_buf;
     gnutls_x509_crt_t cert;
     const char delim;
     size_t len;
     gnutls_datum_t d;
-    int pos1, pos2, tmp_pos1, idx;
+    int pos1, pos2, idx;
     int num_tags;
     gnutls_x509_dn_t dn;
     size_t size;
 
-    CertParser(gnutls_x509_crt_t c) : cert(c), delim(','), pos1(0), pos2(0), idx(0), 
num_tags(G_N_ELEMENTS(tags_idx))
+    CertParser(gnutls_x509_crt_t c) :
+      cert(c),
+      delim(','),
+      len(0),
+      pos1(0),
+      pos2(0),
+      idx(0),
+      num_tags(G_N_ELEMENTS(tags_idx))
     {
 
       gnutls_x509_crt_get_issuer_dn(cert, NULL, &size);
@@ -113,8 +119,12 @@ namespace pan
       tags.insert(quarks_p(cleaned_tags[i],  "serialNumber"));
     }
 
+    CertParser(CertParser const &) = delete;
+    CertParser &operator=(CertParser const &) = delete;
+
     void parse(std::vector<quarks_p>& i, std::vector<quarks_p>& s)
     {
+      char buf[2048];
       while(idx < num_tags)
       {
         std::string::size_type index = iss.find(tags_idx[idx]);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]