From: Kevin McCarthy Date: Sat, 4 Jun 2016 18:32:09 +0000 (-0700) Subject: Various fixes to the sidebar logic. X-Git-Tag: neomutt-20160822~132 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=61faa2a86de614b2bee6decb426003246c5fd8c0;p=neomutt Various fixes to the sidebar logic. 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. --- diff --git a/sidebar.c b/sidebar.c index 7c07eac84..ba23d33f7 100644 --- 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; }