]> granicus.if.org Git - mutt/commitdiff
Use mutt_strlen and mutt_strncmp in sidebar.c.
authorKevin McCarthy <kevin@8t8.us>
Sun, 16 Oct 2016 22:12:33 +0000 (15:12 -0700)
committerKevin McCarthy <kevin@8t8.us>
Sun, 16 Oct 2016 22:12:33 +0000 (15:12 -0700)
This prevents a segv if folder is unset.

sidebar.c

index 5b7edafdfd749b2cea6e139c216d25421d6efb8e..77a2a03b24a3b016ccc2b889085b609ac1b9507d 100644 (file)
--- a/sidebar.c
+++ b/sidebar.c
@@ -220,7 +220,7 @@ static void make_sidebar_entry (char *buf, unsigned int buflen, int width, char
 
   /* Force string to be exactly the right width */
   int w = mutt_strwidth (buf);
-  int s = strlen (buf);
+  int s = mutt_strlen (buf);
   width = MIN(buflen, width);
   if (w < width)
   {
@@ -587,13 +587,15 @@ static void draw_sidebar (int num_rows, int num_cols, int div_width)
     }
 
     /* compute length of Maildir without trailing separator */
-    size_t maildirlen = strlen (Maildir);
-    if (SidebarDelimChars && strchr (SidebarDelimChars, Maildir[maildirlen - 1]))
+    size_t maildirlen = mutt_strlen (Maildir);
+    if (maildirlen &&
+        SidebarDelimChars &&
+        strchr (SidebarDelimChars, Maildir[maildirlen - 1]))
       maildirlen--;
 
     /* check whether Maildir is a prefix of the current folder's path */
     short maildir_is_prefix = 0;
-    if ((strlen (b->path) > maildirlen) && (strncmp (Maildir, b->path, maildirlen) == 0))
+    if ((mutt_strlen (b->path) > maildirlen) && (mutt_strncmp (Maildir, b->path, maildirlen) == 0))
       maildir_is_prefix = 1;
 
     /* calculate depth of current folder and generate its display name with indented spaces */
@@ -604,7 +606,7 @@ static void draw_sidebar (int num_rows, int num_cols, int div_width)
     {
       /* disregard a trailing separator, so strlen() - 2 */
       sidebar_folder_name = b->path;
-      for (i = strlen (sidebar_folder_name) - 2; i >= 0; i--)
+      for (i = mutt_strlen (sidebar_folder_name) - 2; i >= 0; i--)
       {
         if (SidebarDelimChars &&
             strchr (SidebarDelimChars, sidebar_folder_name[i]))
@@ -622,7 +624,7 @@ static void draw_sidebar (int num_rows, int num_cols, int div_width)
       const char *tmp_folder_name;
       int lastsep = 0;
       tmp_folder_name = b->path + maildirlen + 1;
-      int tmplen = (int) strlen (tmp_folder_name) - 1;
+      int tmplen = (int) mutt_strlen (tmp_folder_name) - 1;
       for (i = 0; i < tmplen; i++)
       {
         if (SidebarDelimChars && strchr (SidebarDelimChars, tmp_folder_name[i]))
@@ -635,8 +637,8 @@ static void draw_sidebar (int num_rows, int num_cols, int div_width)
       {
         if (option (OPTSIDEBARSHORTPATH))
           tmp_folder_name += lastsep;  /* basename */
-        int sfn_len = strlen (tmp_folder_name) +
-                      sidebar_folder_depth*strlen (NONULL(SidebarIndentString)) + 1;
+        int sfn_len = mutt_strlen (tmp_folder_name) +
+                      sidebar_folder_depth*mutt_strlen (SidebarIndentString) + 1;
         sidebar_folder_name = safe_malloc (sfn_len);
         sidebar_folder_name[0]=0;
         for (i=0; i < sidebar_folder_depth; i++)