Fix buffer clash (one already present, one added in 3.16.0-254-gb9c4e27),
[claws.git] / src / summaryview.c
index f4298a99ed4751073609faf023624cc83e8a5c84..d6f179ee7fbdc5369ef35777792f525bf9c75451 100644 (file)
@@ -3364,7 +3364,8 @@ static inline void summary_set_header(SummaryView *summaryview, gchar *text[],
 {
        static gchar date_modified[80];
        static gchar col_score[11];
-       static gchar buf[BUFFSIZE], tmp1[BUFFSIZE], tmp2[BUFFSIZE], tmp3[BUFFSIZE];
+       static gchar from_buf[BUFFSIZE], to_buf[BUFFSIZE];
+       static gchar tmp1[BUFFSIZE], tmp2[BUFFSIZE], tmp3[BUFFSIZE];
        gint *col_pos = summaryview->col_pos;
        gchar *from_text = NULL, *to_text = NULL, *tags_text = NULL;
        gboolean should_swap = FALSE;
@@ -3454,9 +3455,9 @@ static inline void summary_set_header(SummaryView *summaryview, gchar *text[],
        } else {
                gchar *tmp = summary_complete_address(msginfo->from);
                if (tmp) {
-                       strncpy2(buf, tmp, sizeof(buf));
+                       strncpy2(from_buf, tmp, sizeof(from_buf));
                        g_free(tmp);
-                       from_text = buf;
+                       from_text = from_buf;
                } else {
                        if (prefs_common.summary_from_show == SHOW_NAME)
                                from_text = msginfo->fromname;
@@ -3481,9 +3482,16 @@ static inline void summary_set_header(SummaryView *summaryview, gchar *text[],
        if (!to_text)
                to_text = _("(No Recipient)");
        else {
-               if (prefs_common.summary_from_show == SHOW_NAME)
-                       to_text = procheader_get_fromname(to_text);
-               else if (prefs_common.summary_from_show == SHOW_ADDR)
+               if (prefs_common.summary_from_show == SHOW_NAME) {
+                       gchar *tmp = procheader_get_fromname(to_text);
+                       /* need to keep to_text pointing to stack, so heap-allocated
+                        * string from procheader_get_fromname() will be copied to to_buf */
+                       if (tmp != NULL) {
+                               strncpy2(to_buf, tmp, sizeof(to_buf));
+                               g_free(tmp);
+                               to_text = to_buf;
+                       }
+               } else if (prefs_common.summary_from_show == SHOW_ADDR)
                        extract_address(to_text);
        }
 
@@ -3493,10 +3501,12 @@ static inline void summary_set_header(SummaryView *summaryview, gchar *text[],
        } else {
                if (prefs_common.use_addr_book) {
                        gchar *tmp = summary_complete_address(to_text);
+                       /* need to keep to_text pointing to stack, so heap-allocated
+                        * string from summary_complete_address() will be copied to to_buf */
                        if (tmp) {
-                               strncpy2(buf, tmp, sizeof(buf));
+                               strncpy2(to_buf, tmp, sizeof(to_buf));
                                g_free(tmp);
-                               to_text = buf;
+                               to_text = to_buf;
                        } else {
                                to_text = to_text ? to_text : _("(No From)");
                        }
@@ -7291,7 +7301,7 @@ static void summary_sort_by_column_click(SummaryView *summaryview,
                             summaryview->sort_type == SORT_ASCENDING
                             ? SORT_DESCENDING : SORT_ASCENDING);
        else
-               summary_sort(summaryview, sort_key, SORT_ASCENDING);
+               summary_sort(summaryview, sort_key, summaryview->sort_type);
 
        node = GTK_CMCTREE_NODE(GTK_CMCLIST(summaryview->ctree)->row_list);