]> granicus.if.org Git - neomutt/commitdiff
browser.c: Convert prefix to Buffer
authorKevin McCarthy <kevin@8t8.us>
Tue, 12 Mar 2019 04:46:56 +0000 (12:46 +0800)
committerRichard Russon <rich@flatcap.org>
Tue, 9 Apr 2019 13:04:55 +0000 (14:04 +0100)
Co-authored-by: Richard Russon <rich@flatcap.org>
browser.c

index cb93dd1d96db8b9e3a84e2a0778a7ed4441b72c0..b54e7e6e6e161d8a2e1b1b494280bfdc5876fb8b 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -1105,7 +1105,6 @@ void mutt_select_file(char *file, size_t filelen, SelectFileFlags flags,
                       char ***files, int *numfiles)
 {
   char buf[PATH_MAX];
-  char prefix[PATH_MAX] = "";
   char helpstr[1024];
   char title[256];
   struct BrowserState state = { 0 };
@@ -1121,6 +1120,10 @@ void mutt_select_file(char *file, size_t filelen, SelectFileFlags flags,
 
   mailbox = mailbox && folder;
 
+  struct Buffer *OldLastDir = mutt_buffer_pool_get();
+  struct Buffer *tmp = mutt_buffer_pool_get();
+  struct Buffer *prefix = mutt_buffer_pool_get();
+
   if (!LastDir)
   {
     LastDir = mutt_buffer_alloc(PATH_MAX);
@@ -1131,7 +1134,7 @@ void mutt_select_file(char *file, size_t filelen, SelectFileFlags flags,
   if (OptNews)
   {
     if (file[0] != '\0')
-      mutt_str_strfcpy(prefix, file, sizeof(prefix));
+      mutt_buffer_strcpy(prefix, file);
     else
     {
       struct NntpAccountData *adata = CurrentNewsSrv;
@@ -1191,9 +1194,9 @@ void mutt_select_file(char *file, size_t filelen, SelectFileFlags flags,
       }
 
       if ((i <= 0) && (file[0] != '/'))
-        mutt_str_strfcpy(prefix, file, sizeof(prefix));
+        mutt_buffer_strcpy(prefix, file);
       else
-        mutt_str_strfcpy(prefix, file + i + 1, sizeof(prefix));
+        mutt_buffer_strcpy(prefix, file + i + 1);
       kill_prefix = true;
 #ifdef USE_IMAP
     }
@@ -1298,7 +1301,7 @@ void mutt_select_file(char *file, size_t filelen, SelectFileFlags flags,
       if (!state.imap_browse)
 #endif
   {
-    if (examine_directory(NULL, &state, mutt_b2s(LastDir), prefix) == -1)
+    if (examine_directory(NULL, &state, mutt_b2s(LastDir), mutt_b2s(prefix)) == -1)
       goto bail;
   }
   menu = mutt_menu_new(MENU_FOLDER);
@@ -1319,8 +1322,6 @@ void mutt_select_file(char *file, size_t filelen, SelectFileFlags flags,
 
   init_menu(&state, menu, title, sizeof(title), mailbox);
 
-  struct Buffer *OldLastDir = mutt_buffer_pool_get();
-  struct Buffer *tmp = mutt_buffer_pool_get();
   int op;
   while (true)
   {
@@ -1435,7 +1436,7 @@ void mutt_select_file(char *file, size_t filelen, SelectFileFlags flags,
             destroy_state(&state);
             if (kill_prefix)
             {
-              prefix[0] = '\0';
+              mutt_buffer_reset(prefix);
               kill_prefix = false;
             }
             mailbox = false;
@@ -1451,11 +1452,11 @@ void mutt_select_file(char *file, size_t filelen, SelectFileFlags flags,
             else
 #endif
             {
-              if (examine_directory(menu, &state, mutt_b2s(LastDir), prefix) == -1)
+              if (examine_directory(menu, &state, mutt_b2s(LastDir), mutt_b2s(prefix)) == -1)
               {
                 /* try to restore the old values */
                 mutt_buffer_strcpy(LastDir, mutt_b2s(OldLastDir));
-                if (examine_directory(menu, &state, mutt_b2s(LastDir), prefix) == -1)
+                if (examine_directory(menu, &state, mutt_b2s(LastDir), mutt_b2s(prefix)) == -1)
                 {
                   mutt_buffer_strcpy(LastDir, NONULL(HomeDir));
                   goto bail;
@@ -1695,12 +1696,13 @@ void mutt_select_file(char *file, size_t filelen, SelectFileFlags flags,
               if (S_ISDIR(st.st_mode))
               {
                 destroy_state(&state);
-                if (examine_directory(menu, &state, buf, prefix) == 0)
+                if (examine_directory(menu, &state, buf, mutt_b2s(prefix)) == 0)
                   mutt_buffer_strcpy(LastDir, buf);
                 else
                 {
                   mutt_error(_("Error scanning directory"));
-                  if (examine_directory(menu, &state, mutt_b2s(LastDir), prefix) == -1)
+                  if (examine_directory(menu, &state, mutt_b2s(LastDir),
+                                        mutt_b2s(prefix)) == -1)
                   {
                     goto bail;
                   }
@@ -1868,7 +1870,7 @@ void mutt_select_file(char *file, size_t filelen, SelectFileFlags flags,
           }
         }
         destroy_state(&state);
-        prefix[0] = '\0';
+        mutt_buffer_reset(prefix);
         kill_prefix = false;
 
         if (mailbox)
@@ -1885,7 +1887,7 @@ void mutt_select_file(char *file, size_t filelen, SelectFileFlags flags,
           menu->data = state.entry;
         }
 #endif
-        else if (examine_directory(menu, &state, mutt_b2s(LastDir), prefix) == -1)
+        else if (examine_directory(menu, &state, mutt_b2s(LastDir), mutt_b2s(prefix)) == -1)
           goto bail;
         init_menu(&state, menu, title, sizeof(title), mailbox);
         break;
@@ -2118,6 +2120,7 @@ void mutt_select_file(char *file, size_t filelen, SelectFileFlags flags,
 bail:
   mutt_buffer_pool_release(&OldLastDir);
   mutt_buffer_pool_release(&tmp);
+  mutt_buffer_pool_release(&prefix);
 
   if (menu)
   {