]> granicus.if.org Git - neomutt/commitdiff
Various fixes to the sidebar logic.
authorKevin McCarthy <kevin@8t8.us>
Sat, 4 Jun 2016 18:32:09 +0000 (11:32 -0700)
committerKevin McCarthy <kevin@8t8.us>
Sat, 4 Jun 2016 18:32:09 +0000 (11:32 -0700)
Use strfcpy instead of strncpy.  The current logic could write past
the end of the buffer.

Don't mess with BUFFY next pointers during removal.  The
mutt_parse_mailboxes() is fine, but this is still not something that
should be done inside sidebar.c.

On removal, set next->prev since we can.

Fix unmailboxes logic:
  * only fix the prev pointers once.
  * if we unmailbox the open mailbox, set it to NULL.

Lastly, flag a redraw on mailboxes/unmailboxes.

sidebar.c

index 7c07eac84acc730438c71b26b167752af01f5477..ba23d33f70c20b361084b8f64c480efc6dfab562 100644 (file)
--- a/sidebar.c
+++ b/sidebar.c
@@ -263,10 +263,7 @@ static void make_sidebar_entry (char *buf, unsigned int buflen, int width, char
     return;
 
   sbe.buffy = b;
-  strncpy (sbe.box, box, sizeof (sbe.box) - 1);
-
-  int box_len = strlen (box);
-  sbe.box[box_len] = '\0';
+  strfcpy (sbe.box, box, sizeof (sbe.box));
 
   mutt_FormatString (buf, buflen, 0, width, NONULL(SidebarFormat), cb_format_str, (unsigned long) &sbe, 0);
 
@@ -355,12 +352,9 @@ static BUFFY *buffy_going (const BUFFY *b)
   if (!b)
     return NULL;
 
-  if (b->prev)
-    b->prev->next = NULL;
-
   if (b->next)
   {
-    b->next->prev = NULL;
+    b->next->prev = b->prev;
     return b->next;
   }
 
@@ -974,15 +968,18 @@ void mutt_sb_notify_mailbox (BUFFY *b, int created)
   }
   else
   {
+    BUFFY *replacement = buffy_going (b);
     if (TopBuffy == b)
-      TopBuffy = buffy_going (TopBuffy);
+      TopBuffy = replacement;
     if (OpnBuffy == b)
-      OpnBuffy = buffy_going (OpnBuffy);
+      OpnBuffy = NULL;
     if (HilBuffy == b)
-      HilBuffy = buffy_going (HilBuffy);
+      HilBuffy = replacement;
     if (BotBuffy == b)
-      BotBuffy = buffy_going (BotBuffy);
+      BotBuffy = replacement;
     if (Outgoing == b)
-      Outgoing = buffy_going (Outgoing);
+      Outgoing = replacement;
   }
+
+  SidebarNeedsRedraw = 1;
 }