[pan: 5/9] This fixes some issues detected by compiling with clang




commit c5e293071151263e4e8205355d04ca8e1cc0f286
Author: Thomas Tanner <thosrtanner googlemail com>
Date:   Sun Jun 12 20:47:13 2022 +0100

    This fixes some issues detected by compiling with clang
    
    Also using -fsanitize=undefined
    Currently -fsanitize=address causes the program to crash on startup

 pan/general/quark.cc          | 15 +++++-------
 pan/general/quark.h           | 50 +++++++++++++++------------------------
 pan/gui/group-prefs-dialog.cc | 55 +++++++++++++++++++++++--------------------
 pan/gui/post-ui.cc            |  5 ++--
 4 files changed, 58 insertions(+), 67 deletions(-)
---
diff --git a/pan/general/quark.cc b/pan/general/quark.cc
index d647889..8f7538c 100644
--- a/pan/general/quark.cc
+++ b/pan/general/quark.cc
@@ -17,22 +17,17 @@
  *
  */
 
+#include "quark.h"
+
 #include <config.h>
 
 #include <iostream>
 #include <string>
 #include "string-view.h"
-#include "quark.h"
 
-using namespace pan;
+namespace pan {
 
-#if defined(HAVE_EXT_HASH_SET)
-// preallocate buckets.
-// this might not be portable?
-Quark::lookup_t Quark::_lookup (300000);
-#else
 Quark::lookup_t Quark::_lookup;
-#endif
 
 /***
 ****
@@ -51,9 +46,11 @@ Quark :: dump (std::ostream& o)
 }
 
 std::ostream&
-pan::operator<< (std::ostream& os, const pan::Quark& s)
+operator<< (std::ostream& os, const Quark& s)
 {
   const StringView& v (s.to_view());
   os.write (v.str, v.len);
   return os;
 }
+
+}
diff --git a/pan/general/quark.h b/pan/general/quark.h
index 1472bd8..f4a8b58 100644
--- a/pan/general/quark.h
+++ b/pan/general/quark.h
@@ -27,16 +27,9 @@
 #include <string>
 #include <climits>
 #include <string>
+#include <unordered_set>
 #include <vector>
 
-#if defined(HAVE_TR1_UNORDERED_SET)
-# include <tr1/unordered_set>
-#elif defined(HAVE_EXT_HASH_SET)
-# include <ext/hash_set>
-#else
-# include <set>
-#endif
-
 #include <pan/general/string-view.h>
 
 #ifndef UINT32_MAX
@@ -60,7 +53,7 @@ namespace pan
    * There is, obviously, a tradeoff involved: hashing strings can be
    * expensive, and the refcounted hashtable of strings has its own
    * memory overhead.  So while strings that are likely to be duplicated
-   * or used as keys -- message-ids, author names, and group names 
+   * or used as keys -- message-ids, author names, and group names
    * spring to mind -- they're less appropriate for temporary, unique data.
    *
    * @ingroup general
@@ -89,7 +82,7 @@ namespace pan
       {
         static uint16_t get16bits( const char * in )
         {
-          return (in[0]<<8) | in[1];
+          return (static_cast<uint16_t>(in[0])<<8) | in[1];
         }
 
         /**
@@ -110,32 +103,32 @@ namespace pan
 
           /* Main loop */
           for (;len > 0; len--) {
-              hash  += get16bits (data);
-              uint32_t tmp  = (get16bits (data + 2) << 11) ^ hash;
-              hash   = (hash << 16) ^ tmp;
-              data  += 2*sizeof (uint16_t);
-              hash  += hash >> 11;
+              hash += get16bits (data);
+              uint32_t tmp = (static_cast<uint32_t>(get16bits(data + 2)) << 11) ^ hash;
+              hash = (hash << 16) ^ tmp;
+              data += 2*sizeof (uint16_t);
+              hash += hash >> 11;
           }
 
           /* Handle end cases */
           switch (rem) {
               case 3:
                 hash += get16bits (data);
-                      hash ^= hash << 16;
-                      hash ^= data[sizeof (uint16_t)] << 18;
-                      hash += hash >> 11;
-                      break;
+                hash ^= hash << 16;
+                hash ^= static_cast<uint32_t>(data[sizeof (uint16_t)]) << 18;
+                hash += hash >> 11;
+                break;
 
               case 2:
                 hash += get16bits (data);
-                      hash ^= hash << 11;
-                      hash += hash >> 17;
-                      break;
+                hash ^= hash << 11;
+                hash += hash >> 17;
+                break;
 
               case 1:
                 hash += *data;
-                      hash ^= hash << 10;
-                      hash += hash >> 1;
+                hash ^= hash << 10;
+                hash += hash >> 1;
           }
 
           /* Force "avalanching" of final 127 bits */
@@ -151,13 +144,8 @@ namespace pan
       };
 
 
-#if defined(HAVE_TR1_UNORDERED_SET)
-      typedef std::tr1::unordered_set<Impl, StringViewHash> lookup_t;
-#elif defined(HAVE_EXT_HASH_SET)
-      typedef __gnu_cxx::hash_set<Impl, StringViewHash> lookup_t;
-#else
-      typedef std::set<Impl> lookup_t;
-#endif
+      typedef std::unordered_set<Impl, StringViewHash> lookup_t;
+
       static lookup_t _lookup;
 
       static Impl* init (const StringView& s)
diff --git a/pan/gui/group-prefs-dialog.cc b/pan/gui/group-prefs-dialog.cc
index ffea63d..d1005fd 100644
--- a/pan/gui/group-prefs-dialog.cc
+++ b/pan/gui/group-prefs-dialog.cc
@@ -17,6 +17,8 @@
  *
  */
 
+#include "group-prefs-dialog.h"
+
 #include <config.h>
 #include <glib/gi18n.h>
 #include <glib.h>
@@ -28,7 +30,6 @@
 #include <pan/general/macros.h>
 #include <pan/data/data.h>
 #include "e-charset-combo-box.h"
-#include "group-prefs-dialog.h"
 #include "hig.h"
 #include "pad.h"
 #include "pan-file-entry.h"
@@ -37,8 +38,7 @@
 
 #include <iostream>
 
-using namespace pan;
-
+namespace pan {
 
 namespace
 {
@@ -280,35 +280,40 @@ GroupPrefsDialog :: GroupPrefsDialog (Data            & data,
     g_snprintf (buf, sizeof(buf), _("Properties for %s"), groups[0].c_str());
 
   HIG::workarea_add_section_title (t, &row, buf);
-    HIG :: workarea_add_section_spacer (t, row, 4);
-    w = _charset = e_charset_combo_box_new( );
-    const char* cs = _group_prefs.get_string (groups[0], "character-encoding", "UTF-8").c_str();
-    e_charset_combo_box_set_charset( E_CHARSET_COMBO_BOX(w), cs ? cs : "");
-
-    HIG :: workarea_add_row (t, &row, _("Character _encoding:"), w);
-
-    w = _save_path = file_entry_new (_("Directory for Saving Attachments"));
-    char * pch = g_build_filename (g_get_home_dir(), "News", NULL);
-    std::string dir (_prefs.get_string ("default-save-attachments-path", pch));
-    if (groups.size() == 1)
-      dir = _group_prefs.get_string (groups[0], "default-group-save-path", dir);
-    g_free (pch);
-    file_entry_set (w, dir.c_str());
+  HIG :: workarea_add_section_spacer (t, row, 4);
+  w = _charset = e_charset_combo_box_new( );
 
-    HIG :: workarea_add_row (t, &row, _("Directory for _saving attachments:"), w);
-    w = _profile = create_profiles_combo_box (data, groups, group_prefs);
-    l = HIG :: workarea_add_row (t, &row, _("Posting _profile:"), w);
+  e_charset_combo_box_set_charset(
+    E_CHARSET_COMBO_BOX(w),
+    _group_prefs.get_string (groups[0], "character-encoding", "UTF-8").c_str()
+  );
 
-    gtk_widget_set_sensitive (l, gtk_widget_get_sensitive(w));
+  HIG :: workarea_add_row (t, &row, _("Character _encoding:"), w);
+
+  w = _save_path = file_entry_new (_("Directory for Saving Attachments"));
+  char * pch = g_build_filename (g_get_home_dir(), "News", NULL);
+  std::string dir (_prefs.get_string ("default-save-attachments-path", pch));
+  if (groups.size() == 1)
+    dir = _group_prefs.get_string (groups[0], "default-group-save-path", dir);
+  g_free (pch);
+  file_entry_set (w, dir.c_str());
+
+  HIG :: workarea_add_row (t, &row, _("Directory for _saving attachments:"), w);
+  w = _profile = create_profiles_combo_box (data, groups, group_prefs);
+  l = HIG :: workarea_add_row (t, &row, _("Posting _profile:"), w);
+
+  gtk_widget_set_sensitive (l, gtk_widget_get_sensitive(w));
 #ifdef HAVE_GTKSPELL
-    w = _spellchecker_language = create_spellcheck_combo_box ( groups[0], group_prefs);
-    HIG :: workarea_add_row (t, &row, _("Spellchecker _language:"), w);
+  w = _spellchecker_language = create_spellcheck_combo_box ( groups[0], group_prefs);
+  HIG :: workarea_add_row (t, &row, _("Spellchecker _language:"), w);
 #endif
-    w = _group_color = new_color_button (groups[0], _prefs, _group_prefs, this, dialog);
-    HIG :: workarea_add_row(t, &row, _("Group color:"), w);
+  w = _group_color = new_color_button (groups[0], _prefs, _group_prefs, this, dialog);
+  HIG :: workarea_add_row(t, &row, _("Group color:"), w);
 
   gtk_box_pack_start ( GTK_BOX( gtk_dialog_get_content_area( GTK_DIALOG( dialog))), t, true, true, 0);
   _root = dialog;
   gtk_widget_show_all (t);
 
 }
+
+} //namespace pan
diff --git a/pan/gui/post-ui.cc b/pan/gui/post-ui.cc
index 8eace4d..b7417cc 100644
--- a/pan/gui/post-ui.cc
+++ b/pan/gui/post-ui.cc
@@ -17,6 +17,8 @@
  *
  */
 
+#include "post-ui.h"
+
 #include <config.h>
 #include <fstream>
 #include <iostream>
@@ -51,7 +53,6 @@ extern "C" {
 #include "e-cte-dialog.h"
 #include "pad.h"
 #include "hig.h"
-#include "post-ui.h"
 #include "post.ui.h"
 #include "profiles-dialog.h"
 #include "url.h"
@@ -170,7 +171,7 @@ PostUI:: update_filequeue_label (GtkTreeSelection *selection)
     g_snprintf(
       str,
       sizeof(str),
-      _("Upload queue: %lu tasks, %ld KB (~ %.2f MB) total."),
+      _("Upload queue: %llu tasks, %ld KB (~ %.2f MB) total."),
       tasks.size(),
       kb,
       kb / 1024.0f);


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