]> granicus.if.org Git - neomutt/commitdiff
Tidy some Buffer API, keep most buffers on the stack
authorPietro Cerutti <gahr@gahr.ch>
Tue, 27 Aug 2019 08:48:54 +0000 (08:48 +0000)
committerRichard Russon <rich@flatcap.org>
Sat, 31 Aug 2019 00:48:23 +0000 (01:48 +0100)
58 files changed:
browser.c
commands.c
compress.c
config/dump.c
config/set.c
core/mailbox.c
core/mailbox.h
curs_lib.c
email/parse.c
icommands.c
imap/command.c
imap/imap.c
imap/imap_private.h
imap/util.c
index.c
init.c
main.c
mbox/mbox.c
monitor.c
mutt/base64.c
mutt/buffer.c
mutt/buffer.h
mutt/file.c
mutt/mbyte.c
mutt/path.c
mutt/pool.c
mutt_lua.c
mutt_mailbox.c
muttlib.c
mx.c
notmuch/mutt_notmuch.c
pager.c
pop/pop.c
sidebar.c
status.c
test/Makefile.autosetup
test/base64/mutt_b64_buffer_encode.c
test/buffer/mutt_buffer_add_printf.c
test/buffer/mutt_buffer_addch.c
test/buffer/mutt_buffer_addstr.c
test/buffer/mutt_buffer_addstr_n.c
test/buffer/mutt_buffer_alloc.c
test/buffer/mutt_buffer_concat_path.c
test/buffer/mutt_buffer_fix_dptr.c
test/buffer/mutt_buffer_increase_size.c [deleted file]
test/buffer/mutt_buffer_init.c
test/buffer/mutt_buffer_is_empty.c
test/buffer/mutt_buffer_len.c
test/buffer/mutt_buffer_printf.c
test/buffer/mutt_buffer_reset.c
test/buffer/mutt_buffer_strcpy.c
test/buffer/mutt_buffer_strcpy_n.c
test/config/dump.c
test/file/mutt_buffer_file_expand_fmt_quote.c
test/main.c
test/path/mutt_path_getcwd.c
test/pattern/comp.c
test/regex/mutt_regex_match.c

index 857a0bdb6e2f0f233ffbaf7e5363b0e819b8d905..5c809bd69acfde26abfccc34176a96de7ff243a2 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -99,16 +99,32 @@ static struct Mapping FolderNewsHelp[] = {
 };
 #endif
 
-static struct Buffer *LastDir = NULL;
-static struct Buffer *LastDirBackup = NULL;
+static struct Buffer LastDir = { 0 };
+static struct Buffer LastDirBackup = { 0 };
+
+/**
+ * init_lastdir - Initialise the browser directories
+ *
+ * These keep track of where the browser used to be looking.
+ */
+static void init_lastdir(void)
+{
+  static bool done = false;
+  if (!done)
+  {
+    mutt_buffer_alloc(&LastDir, PATH_MAX);
+    mutt_buffer_alloc(&LastDirBackup, PATH_MAX);
+    done = true;
+  }
+}
 
 /**
  * mutt_browser_cleanup - Clean up working Buffers
  */
 void mutt_browser_cleanup(void)
 {
-  mutt_buffer_free(&LastDir);
-  mutt_buffer_free(&LastDirBackup);
+  mutt_buffer_dealloc(&LastDir);
+  mutt_buffer_dealloc(&LastDirBackup);
 }
 
 /**
@@ -1021,7 +1037,7 @@ static void init_menu(struct BrowserState *state, struct Menu *menu,
     {
       struct Buffer *path = mutt_buffer_pool_get();
       menu->is_mailbox_list = false;
-      mutt_buffer_strcpy(path, mutt_b2s(LastDir));
+      mutt_buffer_strcpy(path, mutt_b2s(&LastDir));
       mutt_buffer_pretty_mailbox(path);
 #ifdef USE_IMAP
       if (state->imap_browse && C_ImapListSubscribed)
@@ -1043,20 +1059,20 @@ static void init_menu(struct BrowserState *state, struct Menu *menu,
    * The goal is to highlight the good directory if LastDir is the parent dir
    * of LastDirBackup (this occurs mostly when one hit "../"). It should also work
    * properly when the user is in examine_mailboxes-mode.  */
-  if (mutt_str_startswith(mutt_b2s(LastDirBackup), mutt_b2s(LastDir), CASE_MATCH))
+  if (mutt_str_startswith(mutt_b2s(&LastDirBackup), mutt_b2s(&LastDir), CASE_MATCH))
   {
     char target_dir[PATH_MAX] = { 0 };
 
 #ifdef USE_IMAP
     /* Check what kind of dir LastDirBackup is. */
-    if (imap_path_probe(mutt_b2s(LastDirBackup), NULL) == MUTT_IMAP)
+    if (imap_path_probe(mutt_b2s(&LastDirBackup), NULL) == MUTT_IMAP)
     {
-      mutt_str_strfcpy(target_dir, mutt_b2s(LastDirBackup), sizeof(target_dir));
+      mutt_str_strfcpy(target_dir, mutt_b2s(&LastDirBackup), sizeof(target_dir));
       imap_clean_path(target_dir, sizeof(target_dir));
     }
     else
 #endif
-      mutt_str_strfcpy(target_dir, strrchr(mutt_b2s(LastDirBackup), '/') + 1,
+      mutt_str_strfcpy(target_dir, strrchr(mutt_b2s(&LastDirBackup), '/') + 1,
                        sizeof(target_dir));
 
     /* If we get here, it means that LastDir is the parent directory of
@@ -1087,7 +1103,7 @@ static void init_menu(struct BrowserState *state, struct Menu *menu,
 static int file_tag(struct Menu *menu, int sel, int act)
 {
   struct FolderFile *ff = &(((struct FolderFile *) menu->data)[sel]);
-  if (S_ISDIR(ff->mode) || (S_ISLNK(ff->mode) && link_is_dir(mutt_b2s(LastDir), ff->name)))
+  if (S_ISDIR(ff->mode) || (S_ISLNK(ff->mode) && link_is_dir(mutt_b2s(&LastDir), ff->name)))
   {
     mutt_error(_("Can't attach a directory"));
     return 0;
@@ -1111,18 +1127,14 @@ static int file_tag(struct Menu *menu, int sel, int act)
  */
 void mutt_browser_select_dir(const char *f)
 {
-  if (!LastDir)
-  {
-    LastDir = mutt_buffer_alloc(PATH_MAX);
-    LastDirBackup = mutt_buffer_alloc(PATH_MAX);
-  }
+  init_lastdir();
 
-  mutt_buffer_strcpy(LastDirBackup, f);
+  mutt_buffer_strcpy(&LastDirBackup, f);
 
   /* Method that will fetch the parent path depending on the type of the path. */
   char buf[PATH_MAX];
-  mutt_get_parent_path(mutt_b2s(LastDirBackup), buf, sizeof(buf));
-  mutt_buffer_strcpy(LastDir, buf);
+  mutt_get_parent_path(mutt_b2s(&LastDirBackup), buf, sizeof(buf));
+  mutt_buffer_strcpy(&LastDir, buf);
 }
 
 /**
@@ -1155,11 +1167,7 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
   struct Buffer *buf = mutt_buffer_pool_get();
   struct Buffer *prefix = mutt_buffer_pool_get();
 
-  if (!LastDir)
-  {
-    LastDir = mutt_buffer_alloc(PATH_MAX);
-    LastDirBackup = mutt_buffer_alloc(PATH_MAX);
-  }
+  init_lastdir();
 
 #ifdef USE_NNTP
   if (OptNews)
@@ -1195,7 +1203,7 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
       state.imap_browse = true;
       if (imap_browse(mutt_b2s(file), &state) == 0)
       {
-        mutt_buffer_strcpy(LastDir, state.folder);
+        mutt_buffer_strcpy(&LastDir, state.folder);
         browser_sort(&state);
       }
     }
@@ -1208,20 +1216,20 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
       if (i > 0)
       {
         if ((mutt_b2s(file))[0] == '/')
-          mutt_buffer_strcpy_n(LastDir, mutt_b2s(file), i);
+          mutt_buffer_strcpy_n(&LastDir, mutt_b2s(file), i);
         else
         {
-          mutt_path_getcwd(LastDir);
-          mutt_buffer_addch(LastDir, '/');
-          mutt_buffer_addstr_n(LastDir, mutt_b2s(file), i);
+          mutt_path_getcwd(&LastDir);
+          mutt_buffer_addch(&LastDir, '/');
+          mutt_buffer_addstr_n(&LastDir, mutt_b2s(file), i);
         }
       }
       else
       {
         if ((mutt_b2s(file))[0] == '/')
-          mutt_buffer_strcpy(LastDir, "/");
+          mutt_buffer_strcpy(&LastDir, "/");
         else
-          mutt_path_getcwd(LastDir);
+          mutt_path_getcwd(&LastDir);
       }
 
       if ((i <= 0) && (mutt_b2s(file)[0] != '/'))
@@ -1267,7 +1275,7 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
        * meaning only with sort methods SUBJECT/DESC for now.  */
       if (CurrentFolder)
       {
-        if (mutt_b2s(LastDir)[0] == '\0')
+        if (mutt_b2s(&LastDir)[0] == '\0')
         {
           /* If browsing in "local"-mode, than we chose to define LastDir to
            * MailDir */
@@ -1279,7 +1287,7 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
             case MUTT_MH:
             case MUTT_MMDF:
               if (C_Folder)
-                mutt_buffer_strcpy(LastDir, C_Folder);
+                mutt_buffer_strcpy(&LastDir, C_Folder);
               else if (C_Spoolfile)
                 mutt_browser_select_dir(C_Spoolfile);
               break;
@@ -1288,7 +1296,7 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
               break;
           }
         }
-        else if (mutt_str_strcmp(CurrentFolder, mutt_b2s(LastDirBackup)) != 0)
+        else if (mutt_str_strcmp(CurrentFolder, mutt_b2s(&LastDirBackup)) != 0)
         {
           mutt_browser_select_dir(CurrentFolder);
         }
@@ -1296,26 +1304,26 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
 
       /* When browser tracking feature is disabled, clear LastDirBackup */
       if (!browser_track)
-        mutt_buffer_reset(LastDirBackup);
+        mutt_buffer_reset(&LastDirBackup);
     }
 
 #ifdef USE_IMAP
-    if (!mailbox && (imap_path_probe(mutt_b2s(LastDir), NULL) == MUTT_IMAP))
+    if (!mailbox && (imap_path_probe(mutt_b2s(&LastDir), NULL) == MUTT_IMAP))
     {
       init_state(&state, NULL);
       state.imap_browse = true;
-      imap_browse(mutt_b2s(LastDir), &state);
+      imap_browse(mutt_b2s(&LastDir), &state);
       browser_sort(&state);
     }
     else
 #endif
     {
-      size_t i = mutt_buffer_len(LastDir);
-      while ((i > 0) && (mutt_b2s(LastDir)[--i] == '/'))
-        LastDir->data[i] = '\0';
-      mutt_buffer_fix_dptr(LastDir);
-      if (mutt_b2s(LastDir)[0] == '\0')
-        mutt_path_getcwd(LastDir);
+      size_t i = mutt_buffer_len(&LastDir);
+      while ((i > 0) && (mutt_b2s(&LastDir)[--i] == '/'))
+        LastDir.data[i] = '\0';
+      mutt_buffer_fix_dptr(&LastDir);
+      if (mutt_b2s(&LastDir)[0] == '\0')
+        mutt_path_getcwd(&LastDir);
     }
   }
 
@@ -1330,7 +1338,7 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
       if (!state.imap_browse)
 #endif
   {
-    if (examine_directory(NULL, &state, mutt_b2s(LastDir), mutt_b2s(prefix)) == -1)
+    if (examine_directory(NULL, &state, mutt_b2s(&LastDir), mutt_b2s(prefix)) == -1)
       goto bail;
   }
   menu = mutt_menu_new(MENU_FOLDER);
@@ -1371,7 +1379,7 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
 
         if (S_ISDIR(state.entry[menu->current].mode) ||
             (S_ISLNK(state.entry[menu->current].mode) &&
-             link_is_dir(mutt_b2s(LastDir), state.entry[menu->current].name))
+             link_is_dir(mutt_b2s(&LastDir), state.entry[menu->current].name))
 #ifdef USE_IMAP
             || state.entry[menu->current].inferiors
 #endif
@@ -1391,7 +1399,7 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
 #endif
           else
           {
-            mutt_buffer_concat_path(buf, mutt_b2s(LastDir),
+            mutt_buffer_concat_path(buf, mutt_b2s(&LastDir),
                                     state.entry[menu->current].name);
           }
 
@@ -1404,61 +1412,61 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
           )
           {
             /* save the old directory */
-            mutt_buffer_strcpy(OldLastDir, mutt_b2s(LastDir));
+            mutt_buffer_strcpy(OldLastDir, mutt_b2s(&LastDir));
 
             if (mutt_str_strcmp(state.entry[menu->current].name, "..") == 0)
             {
-              size_t lastdirlen = mutt_buffer_len(LastDir);
+              size_t lastdirlen = mutt_buffer_len(&LastDir);
               if ((lastdirlen > 1) &&
-                  (mutt_str_strcmp("..", mutt_b2s(LastDir) + lastdirlen - 2) == 0))
+                  (mutt_str_strcmp("..", mutt_b2s(&LastDir) + lastdirlen - 2) == 0))
               {
-                mutt_buffer_addstr(LastDir, "/..");
+                mutt_buffer_addstr(&LastDir, "/..");
               }
               else
               {
                 char *p = NULL;
                 if (lastdirlen > 1)
-                  p = strrchr(mutt_b2s(LastDir) + 1, '/');
+                  p = strrchr(mutt_b2s(&LastDir) + 1, '/');
 
                 if (p)
                 {
                   *p = '\0';
-                  mutt_buffer_fix_dptr(LastDir);
+                  mutt_buffer_fix_dptr(&LastDir);
                 }
                 else
                 {
-                  if (mutt_b2s(LastDir)[0] == '/')
-                    mutt_buffer_strcpy(LastDir, "/");
+                  if (mutt_b2s(&LastDir)[0] == '/')
+                    mutt_buffer_strcpy(&LastDir, "/");
                   else
-                    mutt_buffer_addstr(LastDir, "/..");
+                    mutt_buffer_addstr(&LastDir, "/..");
                 }
               }
             }
             else if (mailbox)
             {
-              mutt_buffer_strcpy(LastDir, state.entry[menu->current].name);
-              mutt_buffer_expand_path(LastDir);
+              mutt_buffer_strcpy(&LastDir, state.entry[menu->current].name);
+              mutt_buffer_expand_path(&LastDir);
             }
 #ifdef USE_IMAP
             else if (state.imap_browse)
             {
-              mutt_buffer_strcpy(LastDir, state.entry[menu->current].name);
+              mutt_buffer_strcpy(&LastDir, state.entry[menu->current].name);
               /* tack on delimiter here */
 
               /* special case "" needs no delimiter */
               struct Url *url = url_parse(state.entry[menu->current].name);
               if (url->path && (state.entry[menu->current].delim != '\0'))
               {
-                mutt_buffer_addch(LastDir, state.entry[menu->current].delim);
+                mutt_buffer_addch(&LastDir, state.entry[menu->current].delim);
               }
               url_free(&url);
             }
 #endif
             else
             {
-              mutt_buffer_concat_path(tmp, mutt_b2s(LastDir),
+              mutt_buffer_concat_path(tmp, mutt_b2s(&LastDir),
                                       state.entry[menu->current].name);
-              mutt_buffer_strcpy(LastDir, mutt_b2s(tmp));
+              mutt_buffer_strcpy(&LastDir, mutt_b2s(tmp));
             }
 
             destroy_state(&state);
@@ -1473,25 +1481,26 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
             {
               init_state(&state, NULL);
               state.imap_browse = true;
-              imap_browse(mutt_b2s(LastDir), &state);
+              imap_browse(mutt_b2s(&LastDir), &state);
               browser_sort(&state);
               menu->data = state.entry;
             }
             else
 #endif
             {
-              if (examine_directory(menu, &state, mutt_b2s(LastDir), mutt_b2s(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), mutt_b2s(prefix)) == -1)
+                mutt_buffer_strcpy(&LastDir, mutt_b2s(OldLastDir));
+                if (examine_directory(menu, &state, mutt_b2s(&LastDir),
+                                      mutt_b2s(prefix)) == -1)
                 {
-                  mutt_buffer_strcpy(LastDir, NONULL(HomeDir));
+                  mutt_buffer_strcpy(&LastDir, NONULL(HomeDir));
                   goto bail;
                 }
               }
               /* resolve paths navigated from GUI */
-              if (mutt_path_realpath(LastDir->data) == 0)
+              if (mutt_path_realpath(LastDir.data) == 0)
                 break;
             }
 
@@ -1513,7 +1522,7 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
           mutt_buffer_strcpy(file, state.entry[menu->current].name);
 #endif
         else
-          mutt_buffer_concat_path(file, mutt_b2s(LastDir),
+          mutt_buffer_concat_path(file, mutt_b2s(&LastDir),
                                   state.entry[menu->current].name);
         /* fallthrough */
 
@@ -1532,7 +1541,7 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
               struct FolderFile ff = state.entry[i];
               if (ff.tagged)
               {
-                mutt_buffer_concat_path(tmp, mutt_b2s(LastDir), ff.name);
+                mutt_buffer_concat_path(tmp, mutt_b2s(&LastDir), ff.name);
                 mutt_buffer_expand_path(tmp);
                 tfiles[j++] = mutt_str_strdup(mutt_b2s(tmp));
               }
@@ -1571,14 +1580,14 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
           break;
         }
 
-        if (imap_mailbox_create(mutt_b2s(LastDir)) == 0)
+        if (imap_mailbox_create(mutt_b2s(&LastDir)) == 0)
         {
           /* TODO: find a way to detect if the new folder would appear in
            *   this window, and insert it without starting over. */
           destroy_state(&state);
           init_state(&state, NULL);
           state.imap_browse = true;
-          imap_browse(mutt_b2s(LastDir), &state);
+          imap_browse(mutt_b2s(&LastDir), &state);
           browser_sort(&state);
           menu->data = state.entry;
           browser_highlight_default(&state, menu);
@@ -1599,7 +1608,7 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
             destroy_state(&state);
             init_state(&state, NULL);
             state.imap_browse = true;
-            imap_browse(mutt_b2s(LastDir), &state);
+            imap_browse(mutt_b2s(&LastDir), &state);
             browser_sort(&state);
             menu->data = state.entry;
             browser_highlight_default(&state, menu);
@@ -1663,14 +1672,14 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
           break;
 #endif
 
-        mutt_buffer_strcpy(buf, mutt_b2s(LastDir));
+        mutt_buffer_strcpy(buf, mutt_b2s(&LastDir));
 #ifdef USE_IMAP
         if (!state.imap_browse)
 #endif
         {
           /* add '/' at the end of the directory name if not already there */
           size_t len = mutt_buffer_len(buf);
-          if ((len > 0) && (mutt_b2s(LastDir)[len - 1] != '/'))
+          if ((len > 0) && (mutt_b2s(&LastDir)[len - 1] != '/'))
             mutt_buffer_addch(buf, '/');
         }
 
@@ -1692,11 +1701,11 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
 #ifdef USE_IMAP
           if (imap_path_probe(mutt_b2s(buf), NULL) == MUTT_IMAP)
           {
-            mutt_buffer_strcpy(LastDir, mutt_b2s(buf));
+            mutt_buffer_strcpy(&LastDir, mutt_b2s(buf));
             destroy_state(&state);
             init_state(&state, NULL);
             state.imap_browse = true;
-            imap_browse(mutt_b2s(LastDir), &state);
+            imap_browse(mutt_b2s(&LastDir), &state);
             browser_sort(&state);
             menu->data = state.entry;
             browser_highlight_default(&state, menu);
@@ -1709,7 +1718,7 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
             {
               /* in case dir is relative, make it relative to LastDir,
                * not current working dir */
-              mutt_buffer_concat_path(tmp, mutt_b2s(LastDir), mutt_b2s(buf));
+              mutt_buffer_concat_path(tmp, mutt_b2s(&LastDir), mutt_b2s(buf));
               mutt_buffer_strcpy(buf, mutt_b2s(tmp));
             }
             /* Resolve path from <chdir>
@@ -1725,11 +1734,11 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
               {
                 destroy_state(&state);
                 if (examine_directory(menu, &state, mutt_b2s(buf), mutt_b2s(prefix)) == 0)
-                  mutt_buffer_strcpy(LastDir, mutt_b2s(buf));
+                  mutt_buffer_strcpy(&LastDir, mutt_b2s(buf));
                 else
                 {
                   mutt_error(_("Error scanning directory"));
-                  if (examine_directory(menu, &state, mutt_b2s(LastDir),
+                  if (examine_directory(menu, &state, mutt_b2s(&LastDir),
                                         mutt_b2s(prefix)) == -1)
                   {
                     goto bail;
@@ -1778,14 +1787,14 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
         {
           init_state(&state, NULL);
           state.imap_browse = true;
-          imap_browse(mutt_b2s(LastDir), &state);
+          imap_browse(mutt_b2s(&LastDir), &state);
           browser_sort(&state);
           menu->data = state.entry;
           init_menu(&state, menu, title, sizeof(title), mailbox);
         }
         else
 #endif
-            if (examine_directory(menu, &state, mutt_b2s(LastDir), NULL) == 0)
+            if (examine_directory(menu, &state, mutt_b2s(&LastDir), NULL) == 0)
           init_menu(&state, menu, title, sizeof(title), mailbox);
         else
         {
@@ -1880,21 +1889,21 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
           if (C_Folder)
           {
             mutt_debug(LL_DEBUG3, "= hit! Folder: %s, LastDir: %s\n", C_Folder,
-                       mutt_b2s(LastDir));
+                       mutt_b2s(&LastDir));
             if (goto_swapper[0] == '\0')
             {
-              if (mutt_str_strcmp(mutt_b2s(LastDir), C_Folder) != 0)
+              if (mutt_str_strcmp(mutt_b2s(&LastDir), C_Folder) != 0)
               {
                 /* Stores into goto_swapper LastDir, and swaps to C_Folder */
-                mutt_str_strfcpy(goto_swapper, mutt_b2s(LastDir), sizeof(goto_swapper));
-                mutt_buffer_strcpy(LastDirBackup, mutt_b2s(LastDir));
-                mutt_buffer_strcpy(LastDir, C_Folder);
+                mutt_str_strfcpy(goto_swapper, mutt_b2s(&LastDir), sizeof(goto_swapper));
+                mutt_buffer_strcpy(&LastDirBackup, mutt_b2s(&LastDir));
+                mutt_buffer_strcpy(&LastDir, C_Folder);
               }
             }
             else
             {
-              mutt_buffer_strcpy(LastDirBackup, mutt_b2s(LastDir));
-              mutt_buffer_strcpy(LastDir, goto_swapper);
+              mutt_buffer_strcpy(&LastDirBackup, mutt_b2s(&LastDir));
+              mutt_buffer_strcpy(&LastDir, goto_swapper);
               goto_swapper[0] = '\0';
             }
           }
@@ -1908,16 +1917,16 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
           examine_mailboxes(menu, &state);
         }
 #ifdef USE_IMAP
-        else if (imap_path_probe(mutt_b2s(LastDir), NULL) == MUTT_IMAP)
+        else if (imap_path_probe(mutt_b2s(&LastDir), NULL) == MUTT_IMAP)
         {
           init_state(&state, NULL);
           state.imap_browse = true;
-          imap_browse(mutt_b2s(LastDir), &state);
+          imap_browse(mutt_b2s(&LastDir), &state);
           browser_sort(&state);
           menu->data = state.entry;
         }
 #endif
-        else if (examine_directory(menu, &state, mutt_b2s(LastDir), mutt_b2s(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;
@@ -1927,7 +1936,7 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
         break;
 
       case OP_BROWSER_NEW_FILE:
-        mutt_buffer_printf(buf, "%s/", mutt_b2s(LastDir));
+        mutt_buffer_printf(buf, "%s/", mutt_b2s(&LastDir));
         /* buf comes from the buffer pool, so defaults to size 1024 */
         if (mutt_get_field(_("New file name: "), buf->data, buf->dsize, MUTT_FILE) == 0)
         {
@@ -1955,7 +1964,7 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
 #endif
             if (S_ISDIR(state.entry[menu->current].mode) ||
                 (S_ISLNK(state.entry[menu->current].mode) &&
-                 link_is_dir(mutt_b2s(LastDir), state.entry[menu->current].name)))
+                 link_is_dir(mutt_b2s(&LastDir), state.entry[menu->current].name)))
         {
           mutt_error(_("Can't view a directory"));
           break;
@@ -1964,7 +1973,7 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
         {
           char buf2[PATH_MAX];
 
-          mutt_path_concat(buf2, mutt_b2s(LastDir),
+          mutt_path_concat(buf2, mutt_b2s(&LastDir),
                            state.entry[menu->current].name, sizeof(buf2));
           struct Body *b = mutt_make_file_attach(buf2);
           if (b)
index a92f3bb5a1d16fac1d0905d7b6815e0f505cab0f..1733e705ca1de28fe102353036dc7df129e4428d 100644 (file)
@@ -842,36 +842,38 @@ void mutt_enter_command(void)
   if ((mutt_get_field(":", buf, sizeof(buf), MUTT_COMMAND) != 0) || !buf[0])
     return;
 
-  struct Buffer *err = mutt_buffer_alloc(256);
-  struct Buffer *token = mutt_buffer_alloc(256);
+  struct Buffer err = { 0 };
+  mutt_buffer_alloc(&err, 256);
+  struct Buffer token = { 0 };
+  mutt_buffer_alloc(&token, 256);
 
   /* check if buf is a valid icommand, else fall back quietly to parse_rc_lines */
-  enum CommandResult rc = mutt_parse_icommand(buf, err);
-  if (!mutt_buffer_is_empty(err))
+  enum CommandResult rc = mutt_parse_icommand(buf, &err);
+  if (!mutt_buffer_is_empty(&err))
   {
     /* since errbuf could potentially contain printf() sequences in it,
      * we must call mutt_error() in this fashion so that vsprintf()
      * doesn't expect more arguments that we passed */
     if (rc == MUTT_CMD_ERROR)
-      mutt_error("%s", err->data);
+      mutt_error("%s", err.data);
     else
-      mutt_warning("%s", err->data);
+      mutt_warning("%s", err.data);
   }
   else if (rc != MUTT_CMD_SUCCESS)
   {
-    rc = mutt_parse_rc_line(buf, token, err);
-    if (!mutt_buffer_is_empty(err))
+    rc = mutt_parse_rc_line(buf, &token, &err);
+    if (!mutt_buffer_is_empty(&err))
     {
       if (rc == MUTT_CMD_SUCCESS) /* command succeeded with message */
-        mutt_message("%s", err->data);
+        mutt_message("%s", err.data);
       else /* error executing command */
-        mutt_error("%s", err->data);
+        mutt_error("%s", err.data);
     }
   }
   /* else successful command */
 
-  mutt_buffer_free(&token);
-  mutt_buffer_free(&err);
+  mutt_buffer_dealloc(&token);
+  mutt_buffer_dealloc(&err);
 }
 
 /**
index 99ca6b338812f0211f13b749552f7f4f5303f034..d4566997ab2511704d279bca45a2357563a84651 100644 (file)
@@ -141,7 +141,7 @@ static int setup_paths(struct Mailbox *m)
 
   /* We will uncompress to /tmp */
   mutt_mktemp(tmp, sizeof(tmp));
-  mutt_buffer_strcpy(m->pathbuf, tmp);
+  mutt_buffer_strcpy(&m->pathbuf, tmp);
 
   FILE *fp = mutt_file_fopen(mailbox_path(m), "w");
   if (!fp)
index 7484a7cd60d8e24a5b5cc9f34cdce8d94c78f130..c64aa28e5a65cb09517c339587a83f3886f309b1 100644 (file)
@@ -208,14 +208,17 @@ bool dump_config(struct ConfigSet *cs, ConfigDumpFlags flags, FILE *fp)
 
   bool result = true;
 
-  struct Buffer *value = mutt_buffer_alloc(256);
-  struct Buffer *initial = mutt_buffer_alloc(256);
-  struct Buffer *tmp = mutt_buffer_alloc(256);
+  struct Buffer value = { 0 };
+  mutt_buffer_alloc(&value, 256);
+  struct Buffer initial = { 0 };
+  mutt_buffer_alloc(&initial, 256);
+  struct Buffer tmp = { 0 };
+  mutt_buffer_alloc(&tmp, 256);
 
   for (size_t i = 0; list[i]; i++)
   {
-    mutt_buffer_reset(value);
-    mutt_buffer_reset(initial);
+    mutt_buffer_reset(&value);
+    mutt_buffer_reset(&initial);
     he = list[i];
     const int type = DTYPE(he->type);
 
@@ -231,7 +234,7 @@ bool dump_config(struct ConfigSet *cs, ConfigDumpFlags flags, FILE *fp)
       if ((flags & CS_DUMP_ONLY_CHANGED) || !(flags & CS_DUMP_HIDE_VALUE) ||
           (flags & CS_DUMP_SHOW_DEFAULTS))
       {
-        int rc = cs_he_string_get(cs, he, value);
+        int rc = cs_he_string_get(cs, he, &value);
         if (CSR_RESULT(rc) != CSR_SUCCESS)
         {
           result = false; /* LCOV_EXCL_LINE */
@@ -240,28 +243,28 @@ bool dump_config(struct ConfigSet *cs, ConfigDumpFlags flags, FILE *fp)
 
         const struct ConfigDef *cdef = he->data;
         if ((type == DT_STRING) && IS_SENSITIVE(*cdef) &&
-            (flags & CS_DUMP_HIDE_SENSITIVE) && !mutt_buffer_is_empty(value))
+            (flags & CS_DUMP_HIDE_SENSITIVE) && !mutt_buffer_is_empty(&value))
         {
-          mutt_buffer_reset(value);
-          mutt_buffer_addstr(value, "***");
+          mutt_buffer_reset(&value);
+          mutt_buffer_addstr(&value, "***");
         }
 
-        if (IS_PATH(he) && (value->data[0] == '/'))
-          mutt_pretty_mailbox(value->data, value->dsize);
+        if (IS_PATH(he) && (value.data[0] == '/'))
+          mutt_pretty_mailbox(value.data, value.dsize);
 
         if ((type != DT_BOOL) && (type != DT_NUMBER) && (type != DT_LONG) &&
             (type != DT_QUAD) && !(flags & CS_DUMP_NO_ESCAPING))
         {
-          mutt_buffer_reset(tmp);
-          pretty_var(value->data, tmp);
-          mutt_buffer_strcpy(value, tmp->data);
+          mutt_buffer_reset(&tmp);
+          pretty_var(value.data, &tmp);
+          mutt_buffer_strcpy(&value, tmp.data);
         }
       }
 
       /* If necessary, get the default value */
       if (flags & (CS_DUMP_ONLY_CHANGED | CS_DUMP_SHOW_DEFAULTS))
       {
-        int rc = cs_he_initial_get(cs, he, initial);
+        int rc = cs_he_initial_get(cs, he, &initial);
         if (CSR_RESULT(rc) != CSR_SUCCESS)
         {
           result = false; /* LCOV_EXCL_LINE */
@@ -269,25 +272,25 @@ bool dump_config(struct ConfigSet *cs, ConfigDumpFlags flags, FILE *fp)
         }
 
         if (IS_PATH(he) && !(he->type & DT_MAILBOX))
-          mutt_pretty_mailbox(initial->data, initial->dsize);
+          mutt_pretty_mailbox(initial.data, initial.dsize);
 
         if ((type != DT_BOOL) && (type != DT_NUMBER) && (type != DT_LONG) &&
             (type != DT_QUAD) && !(flags & CS_DUMP_NO_ESCAPING))
         {
-          mutt_buffer_reset(tmp);
-          pretty_var(initial->data, tmp);
-          mutt_buffer_strcpy(initial, tmp->data);
+          mutt_buffer_reset(&tmp);
+          pretty_var(initial.data, &tmp);
+          mutt_buffer_strcpy(&initial, tmp.data);
         }
       }
     }
 
-    dump_config_neo(cs, he, value, initial, flags, fp);
+    dump_config_neo(cs, he, &value, &initial, flags, fp);
   }
 
   FREE(&list);
-  mutt_buffer_free(&value);
-  mutt_buffer_free(&initial);
-  mutt_buffer_free(&tmp);
+  mutt_buffer_dealloc(&value);
+  mutt_buffer_dealloc(&initial);
+  mutt_buffer_dealloc(&tmp);
 
   return result;
 }
index bf02d7076d01b560991e6e7bd595cbecc322b32e..d1cc0fd63d1227bbbbdb7ae776520469da98fbe1 100644 (file)
@@ -289,20 +289,20 @@ bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[],
   if (!cs || !vars)
     return false;
 
-  struct Buffer *err = mutt_buffer_new();
+  struct Buffer err = { 0 };
 
   bool rc = true;
 
   for (size_t i = 0; vars[i].name; i++)
   {
-    if (!reg_one_var(cs, &vars[i], err))
+    if (!reg_one_var(cs, &vars[i], &err))
     {
-      mutt_debug(LL_DEBUG1, "%s\n", mutt_b2s(err));
+      mutt_debug(LL_DEBUG1, "%s\n", mutt_b2s(&err));
       rc = false;
     }
   }
 
-  mutt_buffer_free(&err);
+  mutt_buffer_dealloc(&err);
   return rc;
 }
 
index 57cf644dcf0b0048000b5cadf9a70298e9acd3a7..fb315ef0e7275fed919eb5dd64373ddc191cd522 100644 (file)
@@ -42,7 +42,7 @@ struct Mailbox *mailbox_new(void)
 {
   struct Mailbox *m = mutt_mem_calloc(1, sizeof(struct Mailbox));
 
-  m->pathbuf = mutt_buffer_new();
+  mutt_buffer_init(&m->pathbuf);
   m->notify = notify_new(m, NT_MAILBOX);
 
   return m;
@@ -63,7 +63,7 @@ void mailbox_free(struct Mailbox **ptr)
   if (m->mdata && m->free_mdata)
     m->free_mdata(&m->mdata);
 
-  mutt_buffer_free(&m->pathbuf);
+  mutt_buffer_dealloc(&m->pathbuf);
   FREE(&m->name);
   FREE(&m->realpath);
   notify_free(&m->notify);
index c874123bb37c92a7bbc800cf7ea241eda466be72..2b11e6752e49c9342b7a8ac6447c1b810a1cc677 100644 (file)
@@ -91,7 +91,7 @@ typedef uint16_t AclFlags;          ///< Flags, e.g. #MUTT_ACL_ADMIN
  */
 struct Mailbox
 {
-  struct Buffer *pathbuf;
+  struct Buffer pathbuf;
   char *realpath;                     ///< Used for duplicate detection, context comparison, and the sidebar
   char *name;                         ///< A short name for the Mailbox
   struct ConfigSubset *sub;           ///< Inherited config items
@@ -186,9 +186,14 @@ void            mailbox_size_add  (struct Mailbox *m, const struct Email *e);
 void            mailbox_size_sub  (struct Mailbox *m, const struct Email *e);
 void            mailbox_update    (struct Mailbox *m);
 
+/**
+ * mailbox_path - Get the Mailbox's path string
+ * @param m Mailbox
+ * @retval ptr Path string
+ */
 static inline const char *mailbox_path(const struct Mailbox *m)
 {
-  return mutt_b2s(m->pathbuf);
+  return mutt_b2s(&m->pathbuf);
 }
 
 #endif /* MUTT_CORE_MAILBOX_H */
index 0abe7c50c3cef7e23fd572d28929c64681be1d23..c027cd416060055c1d3e68917291c8c837786798 100644 (file)
@@ -692,7 +692,7 @@ int mutt_buffer_enter_fname_full(const char *prompt, struct Buffer *fname,
     else
       mutt_unget_event(0, ch.op);
 
-    mutt_buffer_increase_size(fname, 1024);
+    mutt_buffer_alloc(fname, 1024);
     if (mutt_get_field_full(pc, fname->data, fname->dsize,
                             (mailbox ? MUTT_EFILE : MUTT_FILE) | MUTT_CLEAR,
                             multiple, files, numfiles) != 0)
index 28e4ebdad36036a636d6548e374222b66eb9c995..aad0640a60c99e0ab8f916f563d93c5f5aa46f8f 100644 (file)
@@ -81,12 +81,10 @@ void mutt_auto_subscribe(const char *mailto)
         !mutt_regexlist_match(&UnMailLists, mailbox) &&
         !mutt_regexlist_match(&UnSubscribedLists, mailbox))
     {
-      struct Buffer *err = mutt_buffer_new();
       /* mutt_regexlist_add() detects duplicates, so it is safe to
        * try to add here without any checks. */
-      mutt_regexlist_add(&MailLists, mailbox, REG_ICASE, err);
-      mutt_regexlist_add(&SubscribedLists, mailbox, REG_ICASE, err);
-      mutt_buffer_free(&err);
+      mutt_regexlist_add(&MailLists, mailbox, REG_ICASE, NULL);
+      mutt_regexlist_add(&SubscribedLists, mailbox, REG_ICASE, NULL);
     }
   }
 
@@ -115,7 +113,7 @@ static void parse_parameters(struct ParameterList *pl, const char *s, bool allow
    * in quite large parameter values.  avoid frequent reallocs by
    * pre-sizing */
   if (allow_value_spaces)
-    mutt_buffer_increase_size(buf, mutt_str_strlen(s));
+    mutt_buffer_alloc(buf, mutt_str_strlen(s));
 
   mutt_debug(LL_DEBUG2, "'%s'\n", s);
 
index 1e8a6f012f8c873d67dc04753651672bafc93c5b..6c18184195903c9b82a0f92ee3a61a66432f16b2 100644 (file)
@@ -157,20 +157,20 @@ static void dump_macro(struct Buffer *buf, struct Mapping *menu, struct Keymap *
   char key_binding[MAX_SEQ];
   km_expand_key(key_binding, MAX_SEQ, map);
 
-  struct Buffer *tmp = mutt_buffer_new();
-  escape_string(tmp, map->macro);
+  struct Buffer tmp = { 0 };
+  escape_string(&tmp, map->macro);
 
   if (map->desc)
   {
     mutt_buffer_add_printf(buf, "macro %s %s \"%s\" \"%s\"\n", menu->name,
-                           key_binding, tmp->data, map->desc);
+                           key_binding, tmp.data, map->desc);
   }
   else
   {
-    mutt_buffer_add_printf(buf, "macro %s %s \"%s\"\n", menu->name, key_binding, tmp->data);
+    mutt_buffer_add_printf(buf, "macro %s %s \"%s\"\n", menu->name, key_binding, tmp.data);
   }
 
-  mutt_buffer_free(&tmp);
+  mutt_buffer_dealloc(&tmp);
 }
 
 /**
@@ -246,10 +246,11 @@ static enum CommandResult icmd_bind(struct Buffer *buf, struct Buffer *s,
     return MUTT_CMD_ERROR;
   }
 
-  struct Buffer *filebuf = mutt_buffer_alloc(4096);
+  struct Buffer filebuf = { 0 };
+  mutt_buffer_alloc(&filebuf, 4096);
   if (dump_all || (mutt_str_strcasecmp(buf->data, "all") == 0))
   {
-    dump_all_menus(filebuf, bind);
+    dump_all_menus(&filebuf, bind);
   }
   else
   {
@@ -258,21 +259,21 @@ static enum CommandResult icmd_bind(struct Buffer *buf, struct Buffer *s,
     {
       // L10N: '%s' is the (misspelled) name of the menu, e.g. 'index' or 'pager'
       mutt_buffer_printf(err, _("%s: no such menu"), buf->data);
-      mutt_buffer_free(&filebuf);
+      mutt_buffer_dealloc(&filebuf);
       return MUTT_CMD_ERROR;
     }
 
     struct Mapping menu = { buf->data, menu_index };
-    dump_menu(filebuf, &menu, bind);
+    dump_menu(&filebuf, &menu, bind);
   }
 
-  if (mutt_buffer_is_empty(filebuf))
+  if (mutt_buffer_is_empty(&filebuf))
   {
     // L10N: '%s' is the name of the menu, e.g. 'index' or 'pager', it might
     // L10N: also be 'all' when all menus are affected.
     mutt_buffer_printf(err, bind ? _("%s: no binds for this menu") : _("%s: no macros for this menu"),
                        dump_all ? "all" : buf->data);
-    mutt_buffer_free(&filebuf);
+    mutt_buffer_dealloc(&filebuf);
     return MUTT_CMD_ERROR;
   }
 
@@ -282,13 +283,13 @@ static enum CommandResult icmd_bind(struct Buffer *buf, struct Buffer *s,
   {
     // L10N: '%s' is the file name of the temporary file
     mutt_buffer_printf(err, _("Could not create temporary file %s"), tempfile);
-    mutt_buffer_free(&filebuf);
+    mutt_buffer_dealloc(&filebuf);
     return MUTT_CMD_ERROR;
   }
-  fputs(filebuf->data, fp_out);
+  fputs(filebuf.data, fp_out);
 
   mutt_file_fclose(&fp_out);
-  mutt_buffer_free(&filebuf);
+  mutt_buffer_dealloc(&filebuf);
 
   struct Pager info = { 0 };
   if (mutt_do_pager((bind) ? "bind" : "macro", tempfile, MUTT_PAGER_NO_FLAGS, &info) == -1)
index 4c2ff6df08d88fe6bf3ebd8da01ffc4a6f866117..08484798320c6212b50d7783199d17d91aa7e96b 100644 (file)
@@ -139,7 +139,7 @@ static int cmd_queue(struct ImapAccountData *adata, const char *cmdstr, ImapCmdF
   if (!cmd)
     return IMAP_RES_BAD;
 
-  if (mutt_buffer_add_printf(adata->cmdbuf, "%s %s\r\n", cmd->seq, cmdstr) < 0)
+  if (mutt_buffer_add_printf(&adata->cmdbuf, "%s %s\r\n", cmd->seq, cmdstr) < 0)
     return IMAP_RES_BAD;
 
   return 0;
@@ -201,12 +201,12 @@ static int cmd_start(struct ImapAccountData *adata, const char *cmdstr, ImapCmdF
   if (flags & IMAP_CMD_QUEUE)
     return 0;
 
-  if (mutt_buffer_len(adata->cmdbuf) == 0)
+  if (mutt_buffer_len(&adata->cmdbuf) == 0)
     return IMAP_RES_BAD;
 
-  rc = mutt_socket_send_d(adata->conn, adata->cmdbuf->data,
+  rc = mutt_socket_send_d(adata->conn, adata->cmdbuf.data,
                           (flags & IMAP_CMD_PASS) ? IMAP_LOG_PASS : IMAP_LOG_CMD);
-  mutt_buffer_reset(adata->cmdbuf);
+  mutt_buffer_reset(&adata->cmdbuf);
 
   /* unidle when command queue is flushed */
   if (adata->state == IMAP_IDLE)
@@ -1381,7 +1381,7 @@ int imap_cmd_idle(struct ImapAccountData *adata)
     /* successfully entered IDLE state */
     adata->state = IMAP_IDLE;
     /* queue automatic exit when next command is issued */
-    mutt_buffer_addstr(adata->cmdbuf, "DONE\r\n");
+    mutt_buffer_addstr(&adata->cmdbuf, "DONE\r\n");
     rc = IMAP_RES_OK;
   }
   if (rc != IMAP_RES_OK)
index 055852823415ab3b0c01d5fce00ea275747f391f..cd531fa809269c5d38320b37770fe998c723d258 100644 (file)
@@ -725,10 +725,10 @@ int imap_read_literal(FILE *fp, struct ImapAccountData *adata,
 {
   char c;
   bool r = false;
-  struct Buffer *buf = NULL;
+  struct Buffer buf = { 0 };
 
   if (C_DebugLevel >= IMAP_LOG_LTRL)
-    buf = mutt_buffer_alloc(bytes + 10);
+    mutt_buffer_alloc(&buf, bytes + 10);
 
   mutt_debug(LL_DEBUG2, "reading %ld bytes\n", bytes);
 
@@ -739,7 +739,7 @@ int imap_read_literal(FILE *fp, struct ImapAccountData *adata,
       mutt_debug(LL_DEBUG1, "error during read, %ld bytes read\n", pos);
       adata->status = IMAP_FATAL;
 
-      mutt_buffer_free(&buf);
+      mutt_buffer_dealloc(&buf);
       return -1;
     }
 
@@ -759,13 +759,13 @@ int imap_read_literal(FILE *fp, struct ImapAccountData *adata,
     if (pbar && !(pos % 1024))
       mutt_progress_update(pbar, pos, -1);
     if (C_DebugLevel >= IMAP_LOG_LTRL)
-      mutt_buffer_addch(buf, c);
+      mutt_buffer_addch(&buf, c);
   }
 
   if (C_DebugLevel >= IMAP_LOG_LTRL)
   {
-    mutt_debug(IMAP_LOG_LTRL, "\n%s", buf->data);
-    mutt_buffer_free(&buf);
+    mutt_debug(IMAP_LOG_LTRL, "\n%s", buf.data);
+    mutt_buffer_dealloc(&buf);
   }
   return 0;
 }
@@ -1017,7 +1017,7 @@ int imap_exec_msgset(struct Mailbox *m, const char *pre, const char *post,
   int rc;
   int count = 0;
 
-  struct Buffer *cmd = mutt_buffer_new();
+  struct Buffer cmd = { 0 };
 
   /* We make a copy of the headers just in case resorting doesn't give
    exactly the original order (duplicate messages?), because other parts of
@@ -1037,13 +1037,13 @@ int imap_exec_msgset(struct Mailbox *m, const char *pre, const char *post,
 
   do
   {
-    mutt_buffer_reset(cmd);
-    mutt_buffer_add_printf(cmd, "%s ", pre);
-    rc = make_msg_set(m, cmd, flag, changed, invert, &pos);
+    mutt_buffer_reset(&cmd);
+    mutt_buffer_add_printf(&cmd, "%s ", pre);
+    rc = make_msg_set(m, &cmd, flag, changed, invert, &pos);
     if (rc > 0)
     {
-      mutt_buffer_add_printf(cmd, " %s", post);
-      if (imap_exec(adata, cmd->data, IMAP_CMD_QUEUE) != IMAP_EXEC_SUCCESS)
+      mutt_buffer_add_printf(&cmd, " %s", post);
+      if (imap_exec(adata, cmd.data, IMAP_CMD_QUEUE) != IMAP_EXEC_SUCCESS)
       {
         rc = -1;
         goto out;
@@ -1055,7 +1055,7 @@ int imap_exec_msgset(struct Mailbox *m, const char *pre, const char *post,
   rc = count;
 
 out:
-  mutt_buffer_free(&cmd);
+  mutt_buffer_dealloc(&cmd);
   if (oldsort != C_Sort)
   {
     C_Sort = oldsort;
@@ -1520,7 +1520,6 @@ int imap_fast_trash(struct Mailbox *m, char *dest)
   char prompt[1024];
   int rc = -1;
   bool triedcreate = false;
-  struct Buffer *sync_cmd = NULL;
   enum QuadOption err_continue = MUTT_NO;
 
   struct ImapAccountData *adata = imap_adata_get(m);
@@ -1530,7 +1529,7 @@ int imap_fast_trash(struct Mailbox *m, char *dest)
   if (imap_adata_find(dest, &dest_adata, &dest_mdata) < 0)
     return -1;
 
-  sync_cmd = mutt_buffer_new();
+  struct Buffer sync_cmd = { 0 };
 
   /* check that the save-to folder is in the same account */
   if (!mutt_account_match(&(adata->conn->account), &(dest_adata->conn->account)))
@@ -1544,7 +1543,7 @@ int imap_fast_trash(struct Mailbox *m, char *dest)
     if (m->emails[i]->active && m->emails[i]->changed &&
         m->emails[i]->deleted && !m->emails[i]->purge)
     {
-      rc = imap_sync_message_for_copy(m, m->emails[i], sync_cmd, &err_continue);
+      rc = imap_sync_message_for_copy(m, m->emails[i], &sync_cmd, &err_continue);
       if (rc < 0)
       {
         mutt_debug(LL_DEBUG1, "could not sync\n");
@@ -1608,7 +1607,7 @@ int imap_fast_trash(struct Mailbox *m, char *dest)
   rc = IMAP_EXEC_SUCCESS;
 
 out:
-  mutt_buffer_free(&sync_cmd);
+  mutt_buffer_dealloc(&sync_cmd);
   imap_mdata_free((void *) &dest_mdata);
 
   return ((rc == IMAP_EXEC_SUCCESS) ? 0 : -1);
@@ -1873,7 +1872,7 @@ int imap_ac_add(struct Account *a, struct Mailbox *m)
     /* fixup path and realpath, mainly to replace / by /INBOX */
     char buf[1024];
     imap_qualify_path(buf, sizeof(buf), &adata->conn_account, mdata->name);
-    mutt_buffer_strcpy(m->pathbuf, buf);
+    mutt_buffer_strcpy(&m->pathbuf, buf);
     mutt_str_replace(&m->realpath, mailbox_path(m));
 
     m->mdata = mdata;
@@ -2360,7 +2359,6 @@ static int imap_tags_commit(struct Mailbox *m, struct Email *e, char *buf)
   if (!m)
     return -1;
 
-  struct Buffer *cmd = NULL;
   char uid[11];
 
   struct ImapAccountData *adata = imap_adata_get(m);
@@ -2376,44 +2374,40 @@ static int imap_tags_commit(struct Mailbox *m, struct Email *e, char *buf)
   /* Remove old custom flags */
   if (imap_edata_get(e)->flags_remote)
   {
-    cmd = mutt_buffer_new();
-    cmd->dptr = cmd->data;
-    mutt_buffer_addstr(cmd, "UID STORE ");
-    mutt_buffer_addstr(cmd, uid);
-    mutt_buffer_addstr(cmd, " -FLAGS.SILENT (");
-    mutt_buffer_addstr(cmd, imap_edata_get(e)->flags_remote);
-    mutt_buffer_addstr(cmd, ")");
+    struct Buffer cmd = { 0 };
+    mutt_buffer_addstr(&cmd, "UID STORE ");
+    mutt_buffer_addstr(&cmd, uid);
+    mutt_buffer_addstr(&cmd, " -FLAGS.SILENT (");
+    mutt_buffer_addstr(&cmd, imap_edata_get(e)->flags_remote);
+    mutt_buffer_addstr(&cmd, ")");
 
     /* Should we return here, or we are fine and we could
      * continue to add new flags */
-    if (imap_exec(adata, cmd->data, IMAP_CMD_NO_FLAGS) != IMAP_EXEC_SUCCESS)
+    int rc = imap_exec(adata, cmd.data, IMAP_CMD_NO_FLAGS);
+    mutt_buffer_dealloc(&cmd);
+    if (rc != IMAP_EXEC_SUCCESS)
     {
-      mutt_buffer_free(&cmd);
       return -1;
     }
-
-    mutt_buffer_free(&cmd);
   }
 
   /* Add new custom flags */
   if (buf)
   {
-    cmd = mutt_buffer_new();
-    cmd->dptr = cmd->data;
-    mutt_buffer_addstr(cmd, "UID STORE ");
-    mutt_buffer_addstr(cmd, uid);
-    mutt_buffer_addstr(cmd, " +FLAGS.SILENT (");
-    mutt_buffer_addstr(cmd, buf);
-    mutt_buffer_addstr(cmd, ")");
+    struct Buffer cmd = { 0 };
+    mutt_buffer_addstr(&cmd, "UID STORE ");
+    mutt_buffer_addstr(&cmd, uid);
+    mutt_buffer_addstr(&cmd, " +FLAGS.SILENT (");
+    mutt_buffer_addstr(&cmd, buf);
+    mutt_buffer_addstr(&cmd, ")");
 
-    if (imap_exec(adata, cmd->data, IMAP_CMD_NO_FLAGS) != IMAP_EXEC_SUCCESS)
+    int rc = imap_exec(adata, cmd.data, IMAP_CMD_NO_FLAGS);
+    mutt_buffer_dealloc(&cmd);
+    if (rc != IMAP_EXEC_SUCCESS)
     {
       mutt_debug(LL_DEBUG1, "fail to add new flags\n");
-      mutt_buffer_free(&cmd);
       return -1;
     }
-
-    mutt_buffer_free(&cmd);
   }
 
   /* We are good sync them */
@@ -2475,7 +2469,7 @@ int imap_path_canon(char *buf, size_t buflen)
  */
 int imap_expand_path(struct Buffer *buf)
 {
-  mutt_buffer_increase_size(buf, PATH_MAX);
+  mutt_buffer_alloc(buf, PATH_MAX);
   return imap_path_canon(buf->data, PATH_MAX);
 }
 
index dd6d4962e2effeb5411bf073aa3aef8c50aa91f2..b702ee6518f77d8c99e884f1171f1d6450e3ef18 100644 (file)
@@ -199,7 +199,7 @@ struct ImapAccountData
   int cmdslots;
   int nextcmd;
   int lastcmd;
-  struct Buffer *cmdbuf;
+  struct Buffer cmdbuf;
 
   char delim;
   struct Mailbox *mailbox;     /* Current selected mailbox */
index c7c0f9a3649b24bbe4c88daa008f7bad7d57aaab..c3d6b22f72fead57dbcc6d291458875b1fdb0e38 100644 (file)
@@ -73,7 +73,7 @@ void imap_adata_free(void **ptr)
   struct ImapAccountData *adata = *ptr;
 
   FREE(&adata->capstr);
-  mutt_buffer_free(&adata->cmdbuf);
+  mutt_buffer_dealloc(&adata->cmdbuf);
   FREE(&adata->buf);
   FREE(&adata->cmds);
 
@@ -97,7 +97,6 @@ struct ImapAccountData *imap_adata_new(void)
   static unsigned char new_seqid = 'a';
 
   adata->seqid = new_seqid;
-  adata->cmdbuf = mutt_buffer_new();
   adata->cmdslots = C_ImapPipelineDepth + 2;
   adata->cmds = mutt_mem_calloc(adata->cmdslots, sizeof(*adata->cmds));
 
@@ -527,15 +526,15 @@ int imap_hcache_store_uid_seqset(struct ImapMboxData *mdata)
   if (!mdata->hcache)
     return -1;
 
-  struct Buffer *b = mutt_buffer_new();
   /* The seqset is likely large.  Preallocate to reduce reallocs */
-  mutt_buffer_increase_size(b, 8192);
-  imap_msn_index_to_uid_seqset(b, mdata);
-
-  int rc = mutt_hcache_store_raw(mdata->hcache, "/UIDSEQSET", 10, b->data,
-                                 mutt_buffer_len(b) + 1);
-  mutt_debug(LL_DEBUG3, "Stored /UIDSEQSET %s\n", b->data);
-  mutt_buffer_free(&b);
+  struct Buffer b = { 0 };
+  mutt_buffer_alloc(&b, 8192);
+  imap_msn_index_to_uid_seqset(&b, mdata);
+
+  int rc = mutt_hcache_store_raw(mdata->hcache, "/UIDSEQSET", 10, b.data,
+                                 mutt_buffer_len(&b) + 1);
+  mutt_debug(LL_DEBUG3, "Stored /UIDSEQSET %s\n", b.data);
+  mutt_buffer_dealloc(&b);
   return rc;
 }
 
diff --git a/index.c b/index.c
index bf1b48eded5c2c718bf17ad79025b4c4e33117e8..001f3e764c4d6cacfd0ca0ad7279ed9948f9a8a5 100644 (file)
--- a/index.c
+++ b/index.c
@@ -649,7 +649,7 @@ static int main_change_folder(struct Menu *menu, int op, struct Mailbox *m,
   }
 
   /* keepalive failure in mutt_enter_fname may kill connection. #3028 */
-  if (Context && Context->mailbox && (mutt_buffer_is_empty(Context->mailbox->pathbuf)))
+  if (Context && Context->mailbox && (mutt_buffer_is_empty(&Context->mailbox->pathbuf)))
     ctx_free(&Context);
 
   if (Context && Context->mailbox)
@@ -1118,7 +1118,7 @@ int mutt_index_menu(void)
       check = mx_mbox_check(Context->mailbox, &index_hint);
       if (check < 0)
       {
-        if (!Context->mailbox || (mutt_buffer_is_empty(Context->mailbox->pathbuf)))
+        if (!Context->mailbox || (mutt_buffer_is_empty(&Context->mailbox->pathbuf)))
         {
           /* fatal error occurred */
           ctx_free(&Context);
@@ -1938,7 +1938,8 @@ int mutt_index_menu(void)
         }
 
         /* check for a fatal error, or all messages deleted */
-        if (Context && Context->mailbox && mutt_buffer_is_empty(Context->mailbox->pathbuf))
+        if (Context && Context->mailbox &&
+            mutt_buffer_is_empty(&Context->mailbox->pathbuf))
           ctx_free(&Context);
 
         /* if we were in the pager, redisplay the message */
@@ -2213,8 +2214,7 @@ int mutt_index_menu(void)
       {
         bool cont = false; /* Set if we want to continue instead of break */
 
-        struct Buffer *folderbuf = mutt_buffer_pool_get();
-        mutt_buffer_increase_size(folderbuf, PATH_MAX);
+        struct Buffer *folderbuf = mutt_buffer_alloc(mutt_buffer_pool_get(), PATH_MAX);
         struct Mailbox *m = NULL;
         char *cp = NULL;
 #ifdef USE_NNTP
@@ -2236,8 +2236,8 @@ int mutt_index_menu(void)
         else
           cp = _("Open mailbox");
 
-        if ((op == OP_MAIN_NEXT_UNREAD_MAILBOX) && Context &&
-            Context->mailbox && !mutt_buffer_is_empty(Context->mailbox->pathbuf))
+        if ((op == OP_MAIN_NEXT_UNREAD_MAILBOX) && Context && Context->mailbox &&
+            !mutt_buffer_is_empty(&Context->mailbox->pathbuf))
         {
           mutt_buffer_strcpy(folderbuf, mailbox_path(Context->mailbox));
           mutt_buffer_pretty_mailbox(folderbuf);
@@ -2263,7 +2263,7 @@ int mutt_index_menu(void)
         else
         {
           if (C_ChangeFolderNext && Context && Context->mailbox &&
-              mutt_buffer_is_empty(Context->mailbox->pathbuf))
+              mutt_buffer_is_empty(&Context->mailbox->pathbuf))
           {
             mutt_buffer_strcpy(folderbuf, mailbox_path(Context->mailbox));
             mutt_buffer_pretty_mailbox(folderbuf);
diff --git a/init.c b/init.c
index dadc0b483a80561d2bae81e916b211aac6690f88..12cd89064fdf0b916a3ae4f824c34e4ade04dab4 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1338,7 +1338,7 @@ static enum CommandResult parse_mailboxes(struct Buffer *buf, struct Buffer *s,
       continue;
     }
 
-    mutt_buffer_strcpy(m->pathbuf, buf->data);
+    mutt_buffer_strcpy(&m->pathbuf, buf->data);
     /* int rc = */ mx_path_canon2(m, C_Folder);
 
     bool new_account = false;
@@ -2963,10 +2963,9 @@ int mutt_init(bool skip_sys_rc, struct ListHead *commands)
 {
   char buf[1024];
   int need_pause = 0;
-  struct Buffer err;
+  struct Buffer err = { 0 };
 
-  mutt_buffer_init(&err);
-  mutt_buffer_increase_size(&err, 256);
+  mutt_buffer_alloc(&err, 256);
 
   mutt_grouplist_init();
   /* reverse alias keys need to be strdup'ed because of idna conversions */
@@ -3270,14 +3269,16 @@ finish:
  */
 int mutt_query_variables(struct ListHead *queries)
 {
-  struct Buffer *value = mutt_buffer_alloc(256);
-  struct Buffer *tmp = mutt_buffer_alloc(256);
+  struct Buffer value = { 0 };
+  mutt_buffer_alloc(&value, 256);
+  struct Buffer tmp = { 0 };
+  mutt_buffer_alloc(&tmp, 256);
   int rc = 0;
 
   struct ListNode *np = NULL;
   STAILQ_FOREACH(np, queries, entries)
   {
-    mutt_buffer_reset(value);
+    mutt_buffer_reset(&value);
 
     struct HashElem *he = cs_get_elem(Config, np->data);
     if (!he)
@@ -3286,7 +3287,7 @@ int mutt_query_variables(struct ListHead *queries)
       continue;
     }
 
-    int rv = cs_he_string_get(Config, he, value);
+    int rv = cs_he_string_get(Config, he, &value);
     if (CSR_RESULT(rv) != CSR_SUCCESS)
     {
       rc = 1;
@@ -3295,20 +3296,20 @@ int mutt_query_variables(struct ListHead *queries)
 
     int type = DTYPE(he->type);
     if (IS_PATH(he) && !(he->type & DT_MAILBOX))
-      mutt_pretty_mailbox(value->data, value->dsize);
+      mutt_pretty_mailbox(value.data, value.dsize);
 
     if ((type != DT_BOOL) && (type != DT_NUMBER) && (type != DT_LONG) && (type != DT_QUAD))
     {
-      mutt_buffer_reset(tmp);
-      pretty_var(value->data, tmp);
-      mutt_buffer_strcpy(value, tmp->data);
+      mutt_buffer_reset(&tmp);
+      pretty_var(value.data, &tmp);
+      mutt_buffer_strcpy(&value, tmp.data);
     }
 
-    dump_config_neo(Config, he, value, NULL, CS_DUMP_NO_FLAGS, stdout);
+    dump_config_neo(Config, he, &value, NULL, CS_DUMP_NO_FLAGS, stdout);
   }
 
-  mutt_buffer_free(&value);
-  mutt_buffer_free(&tmp);
+  mutt_buffer_dealloc(&value);
+  mutt_buffer_dealloc(&tmp);
 
   return rc; // TEST16: neomutt -Q charset
 }
@@ -3724,29 +3725,32 @@ int mutt_var_value_complete(char *buf, size_t buflen, int pos)
       myvarval = myvar_get(var);
       if (myvarval)
       {
-        struct Buffer *pretty = mutt_buffer_alloc(256);
-        pretty_var(myvarval, pretty);
-        snprintf(pt, buflen - (pt - buf), "%s=%s", var, pretty->data);
-        mutt_buffer_free(&pretty);
+        struct Buffer pretty = { 0 };
+        mutt_buffer_alloc(&pretty, 256);
+        pretty_var(myvarval, &pretty);
+        snprintf(pt, buflen - (pt - buf), "%s=%s", var, pretty.data);
+        mutt_buffer_dealloc(&pretty);
         return 1;
       }
       return 0; /* no such variable. */
     }
     else
     {
-      struct Buffer *value = mutt_buffer_alloc(256);
-      struct Buffer *pretty = mutt_buffer_alloc(256);
-      int rc = cs_he_string_get(Config, he, value);
+      struct Buffer value = { 0 };
+      mutt_buffer_alloc(&value, 256);
+      struct Buffer pretty = { 0 };
+      mutt_buffer_alloc(&pretty, 256);
+      int rc = cs_he_string_get(Config, he, &value);
       if (CSR_RESULT(rc) == CSR_SUCCESS)
       {
-        pretty_var(value->data, pretty);
-        snprintf(pt, buflen - (pt - buf), "%s=%s", var, pretty->data);
-        mutt_buffer_free(&value);
-        mutt_buffer_free(&pretty);
+        pretty_var(value.data, &pretty);
+        snprintf(pt, buflen - (pt - buf), "%s=%s", var, pretty.data);
+        mutt_buffer_dealloc(&value);
+        mutt_buffer_dealloc(&pretty);
         return 0;
       }
-      mutt_buffer_free(&value);
-      mutt_buffer_free(&pretty);
+      mutt_buffer_dealloc(&value);
+      mutt_buffer_dealloc(&pretty);
       return 1;
     }
   }
diff --git a/main.c b/main.c
index 728a35f25571f60d71c21a3293093c7076830e4f..6713d0e0b5921a895372319ba79260df09239889 100644 (file)
--- a/main.c
+++ b/main.c
@@ -144,8 +144,10 @@ static void test_parse_set(void)
     "%s inv%s=42", "%s inv%s?", "%s &%s",     "%s &%s=42", "%s &%s?",
   };
 
-  struct Buffer *tmp = mutt_buffer_alloc(256);
-  struct Buffer *err = mutt_buffer_alloc(256);
+  struct Buffer tmp = { 0 };
+  mutt_buffer_alloc(&tmp, 256);
+  struct Buffer err = { 0 };
+  mutt_buffer_alloc(&err, 256);
   char line[64];
 
   for (size_t v = 0; v < mutt_array_size(vars); v++)
@@ -158,21 +160,21 @@ static void test_parse_set(void)
       // printf("COMMAND %s\n", commands[c]);
       for (size_t t = 0; t < mutt_array_size(tests); t++)
       {
-        mutt_buffer_reset(tmp);
-        mutt_buffer_reset(err);
+        mutt_buffer_reset(&tmp);
+        mutt_buffer_reset(&err);
 
         snprintf(line, sizeof(line), tests[t], commands[c], vars[v]);
         printf("%-26s", line);
-        enum CommandResult rc = mutt_parse_rc_line(line, tmp, err);
-        printf("%2d %s\n", rc, err->data);
+        enum CommandResult rc = mutt_parse_rc_line(line, &tmp, &err);
+        printf("%2d %s\n", rc, err.data);
       }
       printf("\n");
     }
     // printf("\n");
   }
 
-  mutt_buffer_free(&tmp);
-  mutt_buffer_free(&err);
+  mutt_buffer_dealloc(&tmp);
+  mutt_buffer_dealloc(&err);
 }
 
 /**
@@ -187,19 +189,20 @@ static void reset_tilde(struct ConfigSet *cs)
     "record",     "signature",
   };
 
-  struct Buffer *value = mutt_buffer_alloc(256);
+  struct Buffer value = { 0 };
+  mutt_buffer_alloc(&value, 256);
   for (size_t i = 0; i < mutt_array_size(names); i++)
   {
     struct HashElem *he = cs_get_elem(cs, names[i]);
     if (!he)
       continue;
-    mutt_buffer_reset(value);
-    cs_he_initial_get(cs, he, value);
-    mutt_expand_path(value->data, value->dsize);
-    cs_he_initial_set(cs, he, value->data, NULL);
+    mutt_buffer_reset(&value);
+    cs_he_initial_get(cs, he, &value);
+    mutt_expand_path(value.data, value.dsize);
+    cs_he_initial_set(cs, he, value.data, NULL);
     cs_he_reset(cs, he, NULL);
   }
-  mutt_buffer_free(&value);
+  mutt_buffer_dealloc(&value);
 }
 
 /**
@@ -441,7 +444,7 @@ int main(int argc, char *argv[], char *envp[])
   int double_dash = argc, nargc = 1;
   int rc = 1;
   bool repeat_error = false;
-  struct Buffer *folder = mutt_buffer_new();
+  struct Buffer folder = { 0 };
 
   MuttLogger = log_disp_terminal;
 
@@ -520,7 +523,7 @@ int main(int argc, char *argv[], char *envp[])
           mutt_list_insert_tail(&Muttrc, mutt_str_strdup(optarg));
           break;
         case 'f':
-          mutt_buffer_strcpy(folder, optarg);
+          mutt_buffer_strcpy(&folder, optarg);
           explicit_folder = true;
           break;
 #ifdef USE_NNTP
@@ -739,15 +742,14 @@ int main(int argc, char *argv[], char *envp[])
 
   if (new_magic)
   {
-    struct Buffer *err = mutt_buffer_new();
-    int r = cs_str_initial_set(Config, "mbox_type", new_magic, err);
+    struct Buffer err = { 0 };
+    int r = cs_str_initial_set(Config, "mbox_type", new_magic, &err);
     if (CSR_RESULT(r) != CSR_SUCCESS)
     {
-      mutt_error(err->data);
-      mutt_buffer_free(&err);
+      mutt_error(err.data);
+      mutt_buffer_dealloc(&err);
       goto main_curses;
     }
-    mutt_buffer_free(&err);
     cs_str_reset(Config, "mbox_type", NULL);
   }
 
@@ -1148,8 +1150,8 @@ int main(int argc, char *argv[], char *envp[])
         mutt_message(_("No mailbox with new mail"));
         goto main_curses; // TEST37: neomutt -Z (no new mail)
       }
-      mutt_buffer_reset(folder);
-      mutt_mailbox_next_buffer(Context ? Context->mailbox : NULL, folder);
+      mutt_buffer_reset(&folder);
+      mutt_mailbox_next_buffer(Context ? Context->mailbox : NULL, &folder);
 #ifdef USE_IMAP
       C_ImapPassive = passive;
 #endif
@@ -1172,27 +1174,27 @@ int main(int argc, char *argv[], char *envp[])
         mutt_error(_("No incoming mailboxes defined"));
         goto main_curses; // TEST39: neomutt -n -F /dev/null -y
       }
-      mutt_buffer_reset(folder);
-      mutt_buffer_select_file(folder, MUTT_SEL_FOLDER | MUTT_SEL_MAILBOX, NULL, NULL);
-      if (mutt_buffer_len(folder) == 0)
+      mutt_buffer_reset(&folder);
+      mutt_buffer_select_file(&folder, MUTT_SEL_FOLDER | MUTT_SEL_MAILBOX, NULL, NULL);
+      if (mutt_buffer_len(&folder) == 0)
       {
         goto main_ok; // TEST40: neomutt -y (quit selection)
       }
     }
 
-    if (mutt_buffer_len(folder) == 0)
+    if (mutt_buffer_len(&folder) == 0)
     {
       if (C_Spoolfile)
       {
         // Check if C_Spoolfile corresponds a mailboxes' description.
         struct Mailbox *m_desc = mailbox_find_name(C_Spoolfile);
         if (m_desc)
-          mutt_buffer_strcpy(folder, m_desc->realpath);
+          mutt_buffer_strcpy(&folder, m_desc->realpath);
         else
-          mutt_buffer_strcpy(folder, C_Spoolfile);
+          mutt_buffer_strcpy(&folder, C_Spoolfile);
       }
       else if (C_Folder)
-        mutt_buffer_strcpy(folder, C_Folder);
+        mutt_buffer_strcpy(&folder, C_Folder);
       /* else no folder */
     }
 
@@ -1200,23 +1202,23 @@ int main(int argc, char *argv[], char *envp[])
     if (OptNews)
     {
       OptNews = false;
-      mutt_buffer_increase_size(folder, PATH_MAX);
-      nntp_expand_path(folder->data, folder->dsize, &CurrentNewsSrv->conn->account);
+      mutt_buffer_alloc(&folder, PATH_MAX);
+      nntp_expand_path(folder.data, folder.dsize, &CurrentNewsSrv->conn->account);
     }
     else
 #endif
-      mutt_buffer_expand_path(folder);
+      mutt_buffer_expand_path(&folder);
 
-    mutt_str_replace(&CurrentFolder, mutt_b2s(folder));
-    mutt_str_replace(&LastFolder, mutt_b2s(folder));
+    mutt_str_replace(&CurrentFolder, mutt_b2s(&folder));
+    mutt_str_replace(&LastFolder, mutt_b2s(&folder));
 
     if (flags & MUTT_CLI_IGNORE)
     {
       /* check to see if there are any messages in the folder */
-      switch (mx_check_empty(mutt_b2s(folder)))
+      switch (mx_check_empty(mutt_b2s(&folder)))
       {
         case -1:
-          mutt_perror(mutt_b2s(folder));
+          mutt_perror(mutt_b2s(&folder));
           goto main_curses; // TEST41: neomutt -z -f missing
         case 1:
           mutt_error(_("Mailbox is empty"));
@@ -1224,12 +1226,12 @@ int main(int argc, char *argv[], char *envp[])
       }
     }
 
-    mutt_folder_hook(mutt_b2s(folder), NULL);
+    mutt_folder_hook(mutt_b2s(&folder), NULL);
     mutt_startup_shutdown_hook(MUTT_STARTUP_HOOK);
     notify_send(NeoMutt->notify, NT_GLOBAL, NT_GLOBAL_STARTUP, 0);
 
     repeat_error = true;
-    struct Mailbox *m = mx_path_resolve(mutt_b2s(folder));
+    struct Mailbox *m = mx_path_resolve(mutt_b2s(&folder));
     Context = mx_mbox_open(m, ((flags & MUTT_CLI_RO) || C_ReadOnly) ? MUTT_READONLY : MUTT_OPEN_NO_FLAGS);
     if (!Context)
     {
@@ -1271,7 +1273,7 @@ main_curses:
   if (repeat_error && ErrorBufMessage)
     puts(ErrorBuf);
 main_exit:
-  mutt_buffer_free(&folder);
+  mutt_buffer_dealloc(&folder);
   mutt_list_free(&queries);
   crypto_module_free();
   mutt_window_free_all();
index 0f008cbed83026a4bf01957174611641e1357836..005276cb9404d379678d0939ad03259dbd044dd5 100644 (file)
@@ -1495,7 +1495,7 @@ static int mbox_mbox_close(struct Mailbox *m)
   mutt_file_fclose(&adata->fp);
 
   /* fix up the times so mailbox won't get confused */
-  if (m->peekonly && mutt_buffer_is_empty(m->pathbuf) &&
+  if (m->peekonly && mutt_buffer_is_empty(&m->pathbuf) &&
       (mutt_file_timespec_compare(&m->mtime, &adata->atime) > 0))
   {
 #ifdef HAVE_UTIMENSAT
index 11e874d09c75ceba036b75b9925a3de0670b6f99..80e635209865af8cbb5820abc4e943b2d352536f 100644 (file)
--- a/monitor.c
+++ b/monitor.c
@@ -96,7 +96,7 @@ struct MonitorInfo
   dev_t st_dev;
   ino_t st_ino;
   struct Monitor *monitor;
-  struct Buffer *path_buf; /* access via path only (maybe not initialized) */
+  struct Buffer path_buf; /* access via path only (maybe not initialized) */
 };
 
 /**
@@ -217,7 +217,7 @@ static void monitor_info_init(struct MonitorInfo *info)
  */
 static void monitor_info_free(struct MonitorInfo *info)
 {
-  mutt_buffer_free(&info->path_buf);
+  mutt_buffer_dealloc(&info->path_buf);
 }
 
 /**
@@ -347,10 +347,8 @@ static enum ResolveResult monitor_resolve(struct MonitorInfo *info, struct Mailb
   }
   if (fmt)
   {
-    if (!info->path_buf)
-      info->path_buf = mutt_buffer_new();
-    mutt_buffer_printf(info->path_buf, fmt, info->path);
-    info->path = mutt_b2s(info->path_buf);
+    mutt_buffer_printf(&info->path_buf, fmt, info->path);
+    info->path = mutt_b2s(&info->path_buf);
   }
   if (stat(info->path, &sb) != 0)
     return RESOLVE_RES_FAIL_STAT;
index 728e588931fb288f80916123a37abea41f6a71ee..215866a45bc4ca65a96391923a9cfc0cc80e80df 100644 (file)
@@ -193,7 +193,7 @@ size_t mutt_b64_buffer_encode(struct Buffer *buf, const char *in, size_t len)
   if (!buf)
     return 0;
 
-  mutt_buffer_increase_size(buf, MAX((len * 2), 1024));
+  mutt_buffer_alloc(buf, MAX((len * 2), 1024));
   size_t num = mutt_b64_encode(in, len, buf->data, buf->dsize);
   mutt_buffer_fix_dptr(buf);
   return num;
@@ -211,7 +211,7 @@ int mutt_b64_buffer_decode(struct Buffer *buf, const char *in)
   if (!buf)
     return -1;
 
-  mutt_buffer_increase_size(buf, mutt_str_strlen(in));
+  mutt_buffer_alloc(buf, mutt_str_strlen(in));
   int olen = mutt_b64_decode(in, buf->data, buf->dsize);
   /* mutt_from_base64 returns raw bytes, so don't terminate the buffer either */
   if (olen > 0)
index 33f90eb980b484113e38a7081fc6fa9c3466692b..c35a8df63b0d36cf3193c40aca34fdbd596c138d 100644 (file)
@@ -119,7 +119,7 @@ size_t mutt_buffer_addstr_n(struct Buffer *buf, const char *s, size_t len)
     return 0;
 
   if (!buf->data || !buf->dptr || ((buf->dptr + len + 1) > (buf->data + buf->dsize)))
-    mutt_buffer_increase_size(buf, buf->dsize + MAX(128, len + 1));
+    mutt_buffer_alloc(buf, buf->dsize + MAX(128, len + 1));
 
   memcpy(buf->dptr, s, len);
   buf->dptr += len;
@@ -155,7 +155,7 @@ static int buffer_printf(struct Buffer *buf, const char *fmt, va_list ap)
     return 0; /* LCOV_EXCL_LINE */
 
   if (!buf->data || !buf->dptr || (buf->dsize < 128))
-    mutt_buffer_increase_size(buf, 128);
+    mutt_buffer_alloc(buf, 128);
 
   int doff = buf->dptr - buf->data;
   int blen = buf->dsize - doff;
@@ -169,7 +169,7 @@ static int buffer_printf(struct Buffer *buf, const char *fmt, va_list ap)
     blen = ++len - blen;
     if (blen < 128)
       blen = 128;
-    mutt_buffer_increase_size(buf, buf->dsize + blen);
+    mutt_buffer_alloc(buf, buf->dsize + blen);
     len = vsnprintf(buf->dptr, len, fmt, ap_retry);
   }
   if (len > 0)
@@ -289,21 +289,46 @@ bool mutt_buffer_is_empty(const struct Buffer *buf)
 }
 
 /**
- * mutt_buffer_alloc - Create a new Buffer
- * @param size Size of Buffer to create
- * @retval ptr Newly allocated Buffer
+ * mutt_buffer_alloc - Make sure a buffer can store at least new_size bytes
+ * @param buf      Buffer to change
+ * @param new_size New size
+ * @retval buf The buf argument, useful in
+ *     struct Buffer *buf = mutt_buffer_alloc(mutt_buffer_new(), 1024);
  */
-struct Buffer *mutt_buffer_alloc(size_t size)
+struct Buffer *mutt_buffer_alloc(struct Buffer *buf, size_t new_size)
 {
-  struct Buffer *buf = mutt_mem_calloc(1, sizeof(struct Buffer));
-
-  buf->data = mutt_mem_calloc(1, size);
-  buf->dptr = buf->data;
-  buf->dsize = size;
+  if (buf)
+  {
+    if (!buf->dptr)
+      buf->dptr = buf->data;
+
+    if (new_size > buf->dsize)
+    {
+      size_t offset = (buf->dptr && buf->data) ? buf->dptr - buf->data : 0;
+
+      buf->dsize = new_size;
+      mutt_mem_realloc(&buf->data, buf->dsize);
+      buf->dptr = buf->data + offset;
+      /* This ensures an initially NULL buf->data is now properly terminated. */
+      *buf->dptr = '\0';
+    }
+  }
 
   return buf;
 }
 
+/**
+ * mutt_buffer_dealloc - Release the memory allocated by a buffer
+ * @param buf Buffer to change
+ */
+void mutt_buffer_dealloc(struct Buffer *buf)
+{
+  if (!buf || !buf->data)
+    return;
+
+  FREE(&buf->data);
+}
+
 /**
  * mutt_buffer_strcpy - Copy a string into a Buffer
  * @param buf Buffer to overwrite
@@ -331,31 +356,6 @@ void mutt_buffer_strcpy_n(struct Buffer *buf, const char *s, size_t len)
   mutt_buffer_addstr_n(buf, s, len);
 }
 
-/**
- * mutt_buffer_increase_size - Increase the allocated size of a buffer
- * @param buf      Buffer to change
- * @param new_size New size
- */
-void mutt_buffer_increase_size(struct Buffer *buf, size_t new_size)
-{
-  if (!buf)
-    return;
-
-  if (!buf->dptr)
-    buf->dptr = buf->data;
-
-  if (new_size <= buf->dsize)
-    return;
-
-  size_t offset = (buf->dptr && buf->data) ? buf->dptr - buf->data : 0;
-
-  buf->dsize = new_size;
-  mutt_mem_realloc(&buf->data, buf->dsize);
-  buf->dptr = buf->data + offset;
-  /* This ensures an initially NULL buf->data is now properly terminated. */
-  *buf->dptr = '\0';
-}
-
 /**
  * mutt_buffer_len - Calculate the length of a Buffer
  * @param buf Buffer
index e74ac334f8ecea56ebf083626e77ff8c0e85cc02..dcecbbe6043371d4b9f8318a726e6522236bfce2 100644 (file)
@@ -38,15 +38,15 @@ struct Buffer
 };
 
 /* Convert a buffer to a const char * "string" */
-#define mutt_b2s(buf) (buf->data ? (const char *) buf->data : "")
+#define mutt_b2s(buf) ((buf)->data ? (const char *) (buf)->data : "")
 
-#define MoreArgs(buf) (*buf->dptr && (*buf->dptr != ';') && (*buf->dptr != '#'))
+#define MoreArgs(buf) (*(buf)->dptr && (*(buf)->dptr != ';') && (*(buf)->dptr != '#'))
 
-struct Buffer *mutt_buffer_alloc        (size_t size);
+struct Buffer *mutt_buffer_alloc        (struct Buffer *buf, size_t size);
+void           mutt_buffer_dealloc      (struct Buffer *buf);
 void           mutt_buffer_fix_dptr     (struct Buffer *buf);
 void           mutt_buffer_free         (struct Buffer **p);
 struct Buffer *mutt_buffer_from         (const char *seed);
-void           mutt_buffer_increase_size(struct Buffer *buf, size_t new_size);
 struct Buffer *mutt_buffer_init         (struct Buffer *buf);
 bool           mutt_buffer_is_empty     (const struct Buffer *buf);
 size_t         mutt_buffer_len          (const struct Buffer *buf);
index 620bd6fb3bd1d7b21095af97c153f7e5577095d0..8ca0024707653a008a3945cb083bdc63d5de51ec 100644 (file)
@@ -92,10 +92,11 @@ static int mkwrapdir(const char *path, struct Buffer *newfile, struct Buffer *ne
   const char *basename = NULL;
   int rc = 0;
 
-  struct Buffer *parent = mutt_buffer_alloc(PATH_MAX);
-  mutt_buffer_strcpy(parent, NONULL(path));
+  struct Buffer parent = { 0 };
+  mutt_buffer_alloc(&parent, PATH_MAX);
+  mutt_buffer_strcpy(&parent, NONULL(path));
 
-  char *p = strrchr(parent->data, '/');
+  char *p = strrchr(parent.data, '/');
   if (p)
   {
     *p = '\0';
@@ -103,11 +104,11 @@ static int mkwrapdir(const char *path, struct Buffer *newfile, struct Buffer *ne
   }
   else
   {
-    mutt_buffer_strcpy(parent, ".");
+    mutt_buffer_strcpy(&parent, ".");
     basename = path;
   }
 
-  mutt_buffer_printf(newdir, "%s/%s", mutt_b2s(parent), ".muttXXXXXX");
+  mutt_buffer_printf(newdir, "%s/%s", mutt_b2s(&parent), ".muttXXXXXX");
   if (!mkdtemp(newdir->data))
   {
     mutt_debug(LL_DEBUG1, "mkdtemp() failed\n");
@@ -118,7 +119,7 @@ static int mkwrapdir(const char *path, struct Buffer *newfile, struct Buffer *ne
   mutt_buffer_printf(newfile, "%s/%s", newdir->data, NONULL(basename));
 
 cleanup:
-  mutt_buffer_free(&parent);
+  mutt_buffer_dealloc(&parent);
   return rc;
 }
 
@@ -307,23 +308,24 @@ int mutt_file_symlink(const char *oldpath, const char *newpath)
   }
   else
   {
-    struct Buffer *abs_oldpath = mutt_buffer_alloc(PATH_MAX);
+    struct Buffer abs_oldpath = { 0 };
+    mutt_buffer_alloc(&abs_oldpath, PATH_MAX);
 
-    if (!mutt_path_getcwd(abs_oldpath))
+    if (!mutt_path_getcwd(&abs_oldpath))
     {
-      mutt_buffer_free(&abs_oldpath);
+      mutt_buffer_dealloc(&abs_oldpath);
       return -1;
     }
 
-    mutt_buffer_addch(abs_oldpath, '/');
-    mutt_buffer_addstr(abs_oldpath, oldpath);
-    if (symlink(mutt_b2s(abs_oldpath), newpath) == -1)
+    mutt_buffer_addch(&abs_oldpath, '/');
+    mutt_buffer_addstr(&abs_oldpath, oldpath);
+    if (symlink(mutt_b2s(&abs_oldpath), newpath) == -1)
     {
-      mutt_buffer_free(&abs_oldpath);
+      mutt_buffer_dealloc(&abs_oldpath);
       return -1;
     }
 
-    mutt_buffer_free(&abs_oldpath);
+    mutt_buffer_dealloc(&abs_oldpath);
   }
 
   if ((stat(oldpath, &osb) == -1) || (stat(newpath, &nsb) == -1) ||
@@ -465,7 +467,6 @@ int mutt_file_rmtree(const char *path)
     return -1;
 
   struct dirent *de = NULL;
-  struct Buffer *cur = NULL;
   struct stat statbuf;
   int rc = 0;
 
@@ -478,33 +479,33 @@ int mutt_file_rmtree(const char *path)
 
   /* We avoid using the buffer pool for this function, because it
    * invokes recursively to an unknown depth. */
-  cur = mutt_buffer_new();
-  mutt_buffer_increase_size(cur, PATH_MAX);
+  struct Buffer cur = { 0 };
+  mutt_buffer_alloc(&cur, PATH_MAX);
 
   while ((de = readdir(dirp)))
   {
     if ((strcmp(".", de->d_name) == 0) || (strcmp("..", de->d_name) == 0))
       continue;
 
-    mutt_buffer_printf(cur, "%s/%s", path, de->d_name);
+    mutt_buffer_printf(&cur, "%s/%s", path, de->d_name);
     /* XXX make nonrecursive version */
 
-    if (stat(mutt_b2s(cur), &statbuf) == -1)
+    if (stat(mutt_b2s(&cur), &statbuf) == -1)
     {
       rc = 1;
       continue;
     }
 
     if (S_ISDIR(statbuf.st_mode))
-      rc |= mutt_file_rmtree(mutt_b2s(cur));
+      rc |= mutt_file_rmtree(mutt_b2s(&cur));
     else
-      rc |= unlink(mutt_b2s(cur));
+      rc |= unlink(mutt_b2s(&cur));
   }
   closedir(dirp);
 
   rc |= rmdir(path);
 
-  mutt_buffer_free(&cur);
+  mutt_buffer_dealloc(&cur);
   return rc;
 }
 
@@ -522,30 +523,30 @@ int mutt_file_open(const char *path, int flags)
 
   struct stat osb, nsb;
   int fd;
-  struct Buffer *safe_file = NULL;
-  struct Buffer *safe_dir = NULL;
+  struct Buffer safe_file = { 0 };
+  struct Buffer safe_dir = { 0 };
 
   if (flags & O_EXCL)
   {
-    safe_file = mutt_buffer_alloc(PATH_MAX);
-    safe_dir = mutt_buffer_alloc(PATH_MAX);
+    mutt_buffer_alloc(&safe_file, PATH_MAX);
+    mutt_buffer_alloc(&safe_dir, PATH_MAX);
 
-    if (mkwrapdir(path, safe_file, safe_dir) == -1)
+    if (mkwrapdir(path, &safe_file, &safe_dir) == -1)
     {
       fd = -1;
       goto cleanup;
     }
 
-    fd = open(mutt_b2s(safe_file), flags, 0600);
+    fd = open(mutt_b2s(&safe_file), flags, 0600);
     if (fd < 0)
     {
-      rmdir(mutt_b2s(safe_dir));
+      rmdir(mutt_b2s(&safe_dir));
       goto cleanup;
     }
 
     /* NFS and I believe cygwin do not handle movement of open files well */
     close(fd);
-    if (put_file_in_place(path, mutt_b2s(safe_file), mutt_b2s(safe_dir)) == -1)
+    if (put_file_in_place(path, mutt_b2s(&safe_file), mutt_b2s(&safe_dir)) == -1)
     {
       fd = -1;
       goto cleanup;
@@ -565,8 +566,8 @@ int mutt_file_open(const char *path, int flags)
   }
 
 cleanup:
-  mutt_buffer_free(&safe_file);
-  mutt_buffer_free(&safe_dir);
+  mutt_buffer_dealloc(&safe_file);
+  mutt_buffer_dealloc(&safe_dir);
 
   return fd;
 }
@@ -1417,11 +1418,12 @@ int mutt_file_check_empty(const char *path)
  */
 void mutt_buffer_file_expand_fmt_quote(struct Buffer *dest, const char *fmt, const char *src)
 {
-  struct Buffer *tmp = mutt_buffer_alloc(PATH_MAX);
+  struct Buffer tmp = { 0 };
+  mutt_buffer_alloc(&tmp, PATH_MAX);
 
-  mutt_buffer_quote_filename(tmp, src, true);
-  mutt_file_expand_fmt(dest, fmt, mutt_b2s(tmp));
-  mutt_buffer_free(&tmp);
+  mutt_buffer_quote_filename(&tmp, src, true);
+  mutt_file_expand_fmt(dest, fmt, mutt_b2s(&tmp));
+  mutt_buffer_dealloc(&tmp);
 }
 
 /**
index 43abea81b17f4b0f838ca61197b381a29ebb7283..f66e55668828232ed6058a5b1b4e37e91d31dc4a 100644 (file)
@@ -432,7 +432,7 @@ int mutt_mb_filter_unprintable(char **s)
   char *p = *s;
   mbstate_t mbstate1, mbstate2;
 
-  struct Buffer *b = mutt_buffer_new();
+  struct Buffer buf = { 0 };
   memset(&mbstate1, 0, sizeof(mbstate1));
   memset(&mbstate2, 0, sizeof(mbstate2));
   for (; (k = mbrtowc(&wc, p, MB_LEN_MAX, &mbstate1)); p += k)
@@ -449,10 +449,9 @@ int mutt_mb_filter_unprintable(char **s)
       continue;
     k2 = wcrtomb(scratch, wc, &mbstate2);
     scratch[k2] = '\0';
-    mutt_buffer_addstr(b, scratch);
+    mutt_buffer_addstr(&buf, scratch);
   }
   FREE(s);
-  *s = b->data ? b->data : mutt_mem_calloc(1, 1);
-  FREE(&b);
+  *s = buf.data ? buf.data : mutt_mem_calloc(1, 1);
   return 0;
 }
index 9a168f3b8b66688074b2e3b89f6666f96f43e30d..e21a5f95b2749ac9781fc465cf937314d7e68588 100644 (file)
@@ -601,11 +601,11 @@ const char *mutt_path_getcwd(struct Buffer *cwd)
   if (!cwd)
     return NULL;
 
-  mutt_buffer_increase_size(cwd, PATH_MAX);
+  mutt_buffer_alloc(cwd, PATH_MAX);
   char *retval = getcwd(cwd->data, cwd->dsize);
   while (!retval && (errno == ERANGE))
   {
-    mutt_buffer_increase_size(cwd, cwd->dsize + 256);
+    mutt_buffer_alloc(cwd, cwd->dsize + 256);
     retval = getcwd(cwd->data, cwd->dsize);
   }
   if (retval)
index 0c28471a8142193d6176d7994fa980ad633407d9..aecf4d6b386fdc12922f70f720bc47aafc327426 100644 (file)
@@ -43,14 +43,14 @@ static struct Buffer **BufferPool = NULL;
  */
 static void increase_buffer_pool(void)
 {
-  struct Buffer *newbuf;
   BufferPoolLen += BufferPoolIncrement;
   mutt_debug(LL_DEBUG1, "%zu\n", BufferPoolLen);
 
   mutt_mem_realloc(&BufferPool, BufferPoolLen * sizeof(struct Buffer *));
   while (BufferPoolCount < BufferPoolIncrement)
   {
-    newbuf = mutt_buffer_alloc(BufferPoolInitialBufferSize);
+    struct Buffer *newbuf =
+        mutt_buffer_alloc(mutt_buffer_new(), BufferPoolInitialBufferSize);
     BufferPool[BufferPoolCount++] = newbuf;
   }
 }
index e94af0de555cf201a4866ee741dbb99964ad486e..ad2179437e1e9a3cd9a60e9715822cdae1b35e17 100644 (file)
@@ -156,7 +156,8 @@ static int lua_mutt_set(lua_State *l)
   struct ConfigDef *cdef = he->data;
 
   int rc = 0;
-  struct Buffer *err = mutt_buffer_alloc(256);
+  struct Buffer err = { 0 };
+  mutt_buffer_alloc(&err, 256);
 
   switch (DTYPE(cdef->type))
   {
@@ -169,7 +170,7 @@ static int lua_mutt_set(lua_State *l)
     case DT_STRING:
     {
       const char *value = lua_tostring(l, -1);
-      int rv = cs_he_string_set(Config, he, value, err);
+      int rv = cs_he_string_set(Config, he, value, &err);
       if (CSR_RESULT(rv) != CSR_SUCCESS)
         rc = -1;
       break;
@@ -178,7 +179,7 @@ static int lua_mutt_set(lua_State *l)
     case DT_QUAD:
     {
       const intptr_t value = lua_tointeger(l, -1);
-      int rv = cs_he_native_set(Config, he, value, err);
+      int rv = cs_he_native_set(Config, he, value, &err);
       if (CSR_RESULT(rv) != CSR_SUCCESS)
         rc = -1;
       break;
@@ -186,7 +187,7 @@ static int lua_mutt_set(lua_State *l)
     case DT_BOOL:
     {
       const intptr_t value = lua_toboolean(l, -1);
-      int rv = cs_he_native_set(Config, he, value, err);
+      int rv = cs_he_native_set(Config, he, value, &err);
       if (CSR_RESULT(rv) != CSR_SUCCESS)
         rc = -1;
       break;
@@ -197,7 +198,7 @@ static int lua_mutt_set(lua_State *l)
       break;
   }
 
-  mutt_buffer_free(&err);
+  mutt_buffer_dealloc(&err);
   return rc;
 }
 
@@ -245,19 +246,21 @@ static int lua_mutt_get(lua_State *l)
     case DT_SORT:
     case DT_STRING:
     {
-      struct Buffer *value = mutt_buffer_alloc(256);
-      int rc = cs_he_string_get(Config, he, value);
+      struct Buffer value = { 0 };
+      mutt_buffer_alloc(&value, 256);
+      int rc = cs_he_string_get(Config, he, &value);
       if (CSR_RESULT(rc) != CSR_SUCCESS)
       {
-        mutt_buffer_free(&value);
+        mutt_buffer_dealloc(&value);
         return -1;
       }
 
-      struct Buffer *escaped = mutt_buffer_alloc(256);
-      escape_string(escaped, value->data);
-      lua_pushstring(l, escaped->data);
-      mutt_buffer_free(&value);
-      mutt_buffer_free(&escaped);
+      struct Buffer escaped = { 0 };
+      mutt_buffer_alloc(&escaped, 256);
+      escape_string(&escaped, value.data);
+      lua_pushstring(l, escaped.data);
+      mutt_buffer_dealloc(&value);
+      mutt_buffer_dealloc(&escaped);
       return 1;
     }
     case DT_QUAD:
index 726accb067d8cbd0fac4f40debfc3c9fffb506ce..987909ab2089e508fa3586752a8719f12c06479b 100644 (file)
@@ -74,7 +74,7 @@ static void mailbox_check(struct Mailbox *m_cur, struct Mailbox *m_check,
   }
 
   /* check to see if the folder is the currently selected folder before polling */
-  if (!m_cur || mutt_buffer_is_empty(m_cur->pathbuf) ||
+  if (!m_cur || mutt_buffer_is_empty(&m_cur->pathbuf) ||
       (((m_check->magic == MUTT_IMAP) || (m_check->magic == MUTT_NNTP) ||
         (m_check->magic == MUTT_NOTMUCH) || (m_check->magic == MUTT_POP)) ?
            (mutt_str_strcmp(mailbox_path(m_check), mailbox_path(m_cur)) != 0) :
@@ -94,7 +94,7 @@ static void mailbox_check(struct Mailbox *m_cur, struct Mailbox *m_check,
       default:; /* do nothing */
     }
   }
-  else if (C_CheckMboxSize && m_cur && mutt_buffer_is_empty(m_cur->pathbuf))
+  else if (C_CheckMboxSize && m_cur && mutt_buffer_is_empty(&m_cur->pathbuf))
     m_check->size = (off_t) sb.st_size; /* update the size of current folder */
 
 #ifdef USE_SIDEBAR
@@ -303,7 +303,7 @@ void mutt_mailbox_next_buffer(struct Mailbox *m_cur, struct Buffer *s)
       {
         if (np->mailbox->magic == MUTT_NOTMUCH) /* only match real mailboxes */
           continue;
-        mutt_buffer_expand_path(np->mailbox->pathbuf);
+        mutt_buffer_expand_path(&np->mailbox->pathbuf);
         if ((found || (pass > 0)) && np->mailbox->has_new)
         {
           mutt_buffer_strcpy(s, mailbox_path(np->mailbox));
index a6bea70540cff1b016fcc8b3911a44ef08c35cc1..7c58ad63e099e904bd943e4fc74af21fa81d3613 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -227,7 +227,7 @@ void mutt_buffer_expand_path_regex(struct Buffer *buf, bool regex)
           mutt_addrlist_copy(&e->env->to, al, false);
 
           /* TODO: fix mutt_default_save() to use Buffer */
-          mutt_buffer_increase_size(p, PATH_MAX);
+          mutt_buffer_alloc(p, PATH_MAX);
           mutt_default_save(p->data, p->dsize, e);
           mutt_buffer_fix_dptr(p);
 
@@ -691,7 +691,7 @@ void mutt_buffer_pretty_mailbox(struct Buffer *buf)
     return;
   /* This reduces the size of the Buffer, so we can pass it through.
    * We adjust the size just to make sure buf->data is not NULL though */
-  mutt_buffer_increase_size(buf, PATH_MAX);
+  mutt_buffer_alloc(buf, PATH_MAX);
   mutt_pretty_mailbox(buf->data, buf->dsize);
   mutt_buffer_fix_dptr(buf);
 }
@@ -882,24 +882,25 @@ void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const c
       srccopy[n - 1] = '\0';
 
       /* prepare Buffers */
-      struct Buffer *srcbuf = mutt_buffer_from(srccopy);
+      struct Buffer srcbuf = { 0 };
+      mutt_buffer_addstr(&srcbuf, srccopy);
       /* note: we are resetting dptr and *reading* from the buffer, so we don't
        * want to use mutt_buffer_reset(). */
-      srcbuf->dptr = srcbuf->data;
-      struct Buffer *word = mutt_buffer_new();
-      struct Buffer *cmd = mutt_buffer_new();
+      srcbuf.dptr = srcbuf.data;
+      struct Buffer word = { 0 };
+      struct Buffer cmd = { 0 };
 
       /* Iterate expansions across successive arguments */
       do
       {
         /* Extract the command name and copy to command line */
-        mutt_debug(LL_DEBUG3, "fmtpipe +++: %s\n", srcbuf->dptr);
-        if (word->data)
-          *word->data = '\0';
-        mutt_extract_token(word, srcbuf, MUTT_TOKEN_NO_FLAGS);
-        mutt_debug(LL_DEBUG3, "fmtpipe %2d: %s\n", i++, word->data);
-        mutt_buffer_addch(cmd, '\'');
-        mutt_expando_format(tmp, sizeof(tmp), 0, cols, word->data, callback,
+        mutt_debug(LL_DEBUG3, "fmtpipe +++: %s\n", srcbuf.dptr);
+        if (word.data)
+          *word.data = '\0';
+        mutt_extract_token(&word, &srcbuf, MUTT_TOKEN_NO_FLAGS);
+        mutt_debug(LL_DEBUG3, "fmtpipe %2d: %s\n", i++, word.data);
+        mutt_buffer_addch(&cmd, '\'');
+        mutt_expando_format(tmp, sizeof(tmp), 0, cols, word.data, callback,
                             data, flags | MUTT_FORMAT_NOFILTER);
         for (char *p = tmp; p && *p; p++)
         {
@@ -909,20 +910,20 @@ void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const c
              * single-quoted material.  double-quoting instead will lead
              * shell variable expansions, so break out of the single-quoted
              * span, insert a double-quoted single quote, and resume. */
-            mutt_buffer_addstr(cmd, "'\"'\"'");
+            mutt_buffer_addstr(&cmd, "'\"'\"'");
           }
           else
-            mutt_buffer_addch(cmd, *p);
+            mutt_buffer_addch(&cmd, *p);
         }
-        mutt_buffer_addch(cmd, '\'');
-        mutt_buffer_addch(cmd, ' ');
-      } while (MoreArgs(srcbuf));
+        mutt_buffer_addch(&cmd, '\'');
+        mutt_buffer_addch(&cmd, ' ');
+      } while (MoreArgs(&srcbuf));
 
-      mutt_debug(LL_DEBUG3, "fmtpipe > %s\n", cmd->data);
+      mutt_debug(LL_DEBUG3, "fmtpipe > %s\n", cmd.data);
 
       col -= wlen; /* reset to passed in value */
       wptr = buf;  /* reset write ptr */
-      pid_t pid = mutt_create_filter(cmd->data, NULL, &fp_filter, NULL);
+      pid_t pid = mutt_create_filter(cmd.data, NULL, &fp_filter, NULL);
       if (pid != -1)
       {
         int rc;
@@ -977,9 +978,9 @@ void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const c
         *wptr = '\0';
       }
 
-      mutt_buffer_free(&cmd);
-      mutt_buffer_free(&srcbuf);
-      mutt_buffer_free(&word);
+      mutt_buffer_dealloc(&cmd);
+      mutt_buffer_dealloc(&srcbuf);
+      mutt_buffer_dealloc(&word);
       return;
     }
   }
diff --git a/mx.c b/mx.c
index 787b86f8dd0ac149a5e2dc9d16389f04cd7ea75f..b4a4c37795b956d8a7dd8a39d80caf1525f6d0e3 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -1409,7 +1409,7 @@ int mx_path_canon2(struct Mailbox *m, const char *folder)
   if (rc >= 0)
   {
     m->mx_ops = mx_get_ops(m->magic);
-    mutt_buffer_strcpy(m->pathbuf, m->realpath);
+    mutt_buffer_strcpy(&m->pathbuf, m->realpath);
   }
 
   return rc;
@@ -1547,7 +1547,7 @@ struct Mailbox *mx_path_resolve(const char *path)
 
   m = mailbox_new();
   m->flags = MB_HIDDEN;
-  mutt_buffer_strcpy(m->pathbuf, path);
+  mutt_buffer_strcpy(&m->pathbuf, path);
   mx_path_canon2(m, C_Folder);
 
   return m;
index d9cc33cec054a665dd73f132240bc9fd19eef92c..db1d98cc6c3000af334f45ca50d6b6e48f91bda9 100644 (file)
@@ -2388,10 +2388,10 @@ static int nm_mbox_sync(struct Mailbox *m, int *index_hint)
     else
       email_get_fullpath(e, old_file, sizeof(old_file));
 
-    mutt_buffer_strcpy(m->pathbuf, edata->folder);
+    mutt_buffer_strcpy(&m->pathbuf, edata->folder);
     m->magic = edata->magic;
     rc = mh_sync_mailbox_message(m, i, h);
-    mutt_buffer_strcpy(m->pathbuf, uri);
+    mutt_buffer_strcpy(&m->pathbuf, uri);
     m->magic = MUTT_NOTMUCH;
 
     if (rc)
@@ -2411,7 +2411,7 @@ static int nm_mbox_sync(struct Mailbox *m, int *index_hint)
     FREE(&edata->oldpath);
   }
 
-  mutt_buffer_strcpy(m->pathbuf, uri);
+  mutt_buffer_strcpy(&m->pathbuf, uri);
   m->magic = MUTT_NOTMUCH;
 
   nm_db_release(m);
diff --git a/pager.c b/pager.c
index 7b10fef5c1a48efece8b05491ca340a42e6e90d0..bb59be2468f6974084e9bf8a35c8d56e35a98211 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -2243,7 +2243,6 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P
 {
   static char searchbuf[256] = { 0 };
   char buf[1024];
-  struct Buffer *helpstr = NULL;
   int ch = 0, rc = -1;
   bool first = true;
   int searchctx = 0;
@@ -2301,9 +2300,9 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P
     (rd.line_info[i].syntax)[0].last = -1;
   }
 
-  helpstr = mutt_buffer_new();
+  struct Buffer helpstr = { 0 };
   mutt_compile_help(buf, sizeof(buf), MENU_PAGER, PagerHelp);
-  mutt_buffer_strcpy(helpstr, buf);
+  mutt_buffer_strcpy(&helpstr, buf);
   if (IsEmail(extra))
   {
     mutt_compile_help(buf, sizeof(buf), MENU_PAGER,
@@ -2312,16 +2311,16 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P
                           PagerNewsHelpExtra :
 #endif
                           PagerHelpExtra);
-    mutt_buffer_addch(helpstr, ' ');
-    mutt_buffer_addstr(helpstr, buf);
+    mutt_buffer_addch(&helpstr, ' ');
+    mutt_buffer_addstr(&helpstr, buf);
   }
   if (!InHelp)
   {
     mutt_make_help(buf, sizeof(buf), _("Help"), MENU_PAGER, OP_HELP);
-    mutt_buffer_addch(helpstr, ' ');
-    mutt_buffer_addstr(helpstr, buf);
+    mutt_buffer_addch(&helpstr, ' ');
+    mutt_buffer_addstr(&helpstr, buf);
   }
-  rd.helpstr = mutt_b2s(helpstr);
+  rd.helpstr = mutt_b2s(&helpstr);
 
   rd.index_status_window = mutt_window_new();
   rd.index_window = mutt_window_new();
@@ -2381,7 +2380,7 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P
       int check = mx_mbox_check(Context->mailbox, &index_hint);
       if (check < 0)
       {
-        if (!Context->mailbox || mutt_buffer_is_empty(Context->mailbox->pathbuf))
+        if (!Context->mailbox || mutt_buffer_is_empty(&Context->mailbox->pathbuf))
         {
           /* fatal error occurred */
           ctx_free(&Context);
@@ -3582,7 +3581,7 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P
   mutt_menu_free(&pager_menu);
   mutt_menu_free(&rd.menu);
 
-  mutt_buffer_free(&helpstr);
+  mutt_buffer_dealloc(&helpstr);
   mutt_window_free(&rd.index_status_window);
   mutt_window_free(&rd.index_window);
   mutt_window_free(&rd.pager_status_window);
index 98db515b07cd0ddb0cf973c5a056a8aecfd6d7e0..f86b52bf4af888f2543276959db48b30a036b99f 100644 (file)
--- a/pop/pop.c
+++ b/pop/pop.c
@@ -831,7 +831,7 @@ static int pop_mbox_open(struct Mailbox *m)
   url.path = NULL;
   url_tostring(&url, buf, sizeof(buf), 0);
 
-  mutt_buffer_strcpy(m->pathbuf, buf);
+  mutt_buffer_strcpy(&m->pathbuf, buf);
   mutt_str_replace(&m->realpath, mailbox_path(m));
 
   struct PopAccountData *adata = m->account->adata;
index c2b8673d995d2cd8856f3de112bf9a28ce27c81e..88d8a33f924783e9be1213d62ef36790de3d2625 100644 (file)
--- a/sidebar.c
+++ b/sidebar.c
@@ -879,7 +879,7 @@ static void draw_sidebar(int num_rows, int num_cols, int div_width)
 
     /* check whether C_Folder is a prefix of the current folder's path */
     bool maildir_is_prefix = false;
-    if ((mutt_buffer_len(m->pathbuf) > maildirlen) &&
+    if ((mutt_buffer_len(&m->pathbuf) > maildirlen) &&
         (mutt_str_strncmp(C_Folder, mailbox_path(m), maildirlen) == 0) &&
         C_SidebarDelimChars && strchr(C_SidebarDelimChars, mailbox_path(m)[maildirlen]))
     {
index 8006f47a249ef0548bedbb612fe9a33e85040b07..031da2281d44f89deea17d0f46a09c5545db099e 100644 (file)
--- a/status.c
+++ b/status.c
@@ -152,7 +152,7 @@ static const char *status_format_str(char *buf, size_t buflen, size_t col, int c
       {
         mutt_str_strfcpy(tmp, m->name, sizeof(tmp));
       }
-      else if (m && !mutt_buffer_is_empty(m->pathbuf))
+      else if (m && !mutt_buffer_is_empty(&m->pathbuf))
       {
         mutt_str_strfcpy(tmp, mailbox_path(m), sizeof(tmp));
         mutt_pretty_mailbox(tmp, sizeof(tmp));
index ddfbf18767dfe80a3c7d670b4163c34a22cf2c8d..d9679bf6a336b15e05fe42e1cfe5544077577862 100644 (file)
@@ -47,7 +47,6 @@ BUFFER_OBJS   = test/buffer/mutt_buffer_addch.o \
                  test/buffer/mutt_buffer_fix_dptr.o \
                  test/buffer/mutt_buffer_free.o \
                  test/buffer/mutt_buffer_from.o \
-                 test/buffer/mutt_buffer_increase_size.o \
                  test/buffer/mutt_buffer_init.o \
                  test/buffer/mutt_buffer_is_empty.o \
                  test/buffer/mutt_buffer_len.o \
index 98348e8fdda2c38b6006dda4b08477c5bdc3ee73..ba75ebe645df9b94f3fb229cbdc0f3f753874bc2 100644 (file)
@@ -34,8 +34,8 @@ void test_mutt_b64_buffer_encode(void)
   }
 
   {
-    struct Buffer *buf = mutt_buffer_new();
-    TEST_CHECK(mutt_b64_buffer_encode(buf, NULL, 10) == 0);
-    mutt_buffer_free(&buf);
+    struct Buffer buf = { 0 };
+    TEST_CHECK(mutt_b64_buffer_encode(&buf, NULL, 10) == 0);
+    mutt_buffer_dealloc(&buf);
   }
 }
index 47e3fbd048b79e71538d164ac28f788ceb210f77..1249a7fd6df13e6a4694620d8def6a1ea9080264 100644 (file)
@@ -42,19 +42,19 @@ void test_mutt_buffer_add_printf(void)
 
   {
     TEST_CASE("Empty");
-    struct Buffer *buf = mutt_buffer_new();
-    TEST_CHECK(mutt_buffer_add_printf(buf, "") == 0);
-    TEST_CHECK(strlen(mutt_b2s(buf)) == 0);
-    mutt_buffer_free(&buf);
+    struct Buffer buf = { 0 };
+    TEST_CHECK(mutt_buffer_add_printf(&buf, "") == 0);
+    TEST_CHECK(strlen(mutt_b2s(&buf)) == 0);
+    mutt_buffer_dealloc(&buf);
   }
 
   {
     TEST_CASE("Static");
     const char *str = "apple";
-    struct Buffer *buf = mutt_buffer_new();
-    TEST_CHECK(mutt_buffer_add_printf(buf, str) == 5);
-    TEST_CHECK(strcmp(mutt_b2s(buf), str) == 0);
-    mutt_buffer_free(&buf);
+    struct Buffer buf = { 0 };
+    TEST_CHECK(mutt_buffer_add_printf(&buf, str) == 5);
+    TEST_CHECK(strcmp(mutt_b2s(&buf), str) == 0);
+    mutt_buffer_dealloc(&buf);
   }
 
   {
@@ -63,20 +63,20 @@ void test_mutt_buffer_add_printf(void)
         "apple banana cherry damson elderberry fig guava hawthorn ilama "
         "jackfruit kumquat lemon mango nectarine olive papaya quince raspberry "
         "strawberry tangerine ugli vanilla wolfberry xigua yew ziziphus";
-    struct Buffer *buf = mutt_buffer_new();
-    TEST_CHECK(mutt_buffer_add_printf(buf, str) == 195);
-    TEST_CHECK(strcmp(mutt_b2s(buf), str) == 0);
-    mutt_buffer_free(&buf);
+    struct Buffer buf = { 0 };
+    TEST_CHECK(mutt_buffer_add_printf(&buf, str) == 195);
+    TEST_CHECK(strcmp(mutt_b2s(&buf), str) == 0);
+    mutt_buffer_dealloc(&buf);
   }
 
   {
     TEST_CASE("Varargs");
     const char *str = "apple";
     const char *result = "app 1234567 3.1416";
-    struct Buffer *buf = mutt_buffer_new();
-    TEST_CHECK(mutt_buffer_add_printf(buf, "%.3s %ld %3.4f", str, 1234567, 3.141592654) == 18);
-    TEST_CHECK(strcmp(mutt_b2s(buf), result) == 0);
-    mutt_buffer_free(&buf);
+    struct Buffer buf = { 0 };
+    TEST_CHECK(mutt_buffer_add_printf(&buf, "%.3s %ld %3.4f", str, 1234567, 3.141592654) == 18);
+    TEST_CHECK(strcmp(mutt_b2s(&buf), result) == 0);
+    mutt_buffer_dealloc(&buf);
   }
 
   TEST_CASE("printf to a non-empty Buffer");
index 894370739d4acb55066c3c7fec64804c5483d5c8..58b8fe6ae48a3d50c2a4edee3ab9f7673f190f50 100644 (file)
@@ -34,10 +34,10 @@ void test_mutt_buffer_addch(void)
   }
 
   {
-    struct Buffer *buf = mutt_buffer_new();
-    TEST_CHECK(mutt_buffer_addch(buf, 'a') == 1);
-    TEST_CHECK(strcmp(mutt_b2s(buf), "a") == 0);
-    mutt_buffer_free(&buf);
+    struct Buffer buf = { 0 };
+    TEST_CHECK(mutt_buffer_addch(&buf, 'a') == 1);
+    TEST_CHECK(strcmp(mutt_b2s(&buf), "a") == 0);
+    mutt_buffer_dealloc(&buf);
   }
 
   {
index a7271843f46077f3d6553c2ee458a3fe019b3e28..4d09b201b5ca40b19b394684449f47153817076b 100644 (file)
@@ -39,10 +39,10 @@ void test_mutt_buffer_addstr(void)
   }
 
   {
-    struct Buffer *buf = mutt_buffer_new();
-    TEST_CHECK(mutt_buffer_addstr(buf, "apple") == 5);
-    TEST_CHECK(strcmp(mutt_b2s(buf), "apple") == 0);
-    mutt_buffer_free(&buf);
+    struct Buffer buf = { 0 };
+    TEST_CHECK(mutt_buffer_addstr(&buf, "apple") == 5);
+    TEST_CHECK(strcmp(mutt_b2s(&buf), "apple") == 0);
+    mutt_buffer_dealloc(&buf);
   }
 
   {
index 2213f06b66e4c5dc3d0e525980fb375ecf57970b..afa0a3149c21ac0022bde0ac4f96685132d0af5c 100644 (file)
@@ -48,11 +48,11 @@ void test_mutt_buffer_addstr_n(void)
     for (size_t i = 0; i < mutt_array_size(sizes); i++)
     {
       TEST_CASE_("%ld", sizes[i]);
-      struct Buffer *buf = mutt_buffer_new();
-      TEST_CHECK(mutt_buffer_addstr_n(buf, str, sizes[i]) == sizes[i]);
-      TEST_CHECK(strlen(mutt_b2s(buf)) == MIN(len, sizes[i]));
-      TEST_CHECK(strncmp(mutt_b2s(buf), str, sizes[i]) == 0);
-      mutt_buffer_free(&buf);
+      struct Buffer buf = { 0 };
+      TEST_CHECK(mutt_buffer_addstr_n(&buf, str, sizes[i]) == sizes[i]);
+      TEST_CHECK(strlen(mutt_b2s(&buf)) == MIN(len, sizes[i]));
+      TEST_CHECK(strncmp(mutt_b2s(&buf), str, sizes[i]) == 0);
+      mutt_buffer_dealloc(&buf);
     }
   }
 
index 96c6fb9e05e89eff3b841bb140769d5cf1f6b7ab..7c766f2027969e1cb0a8f971821f503ca906cf6e 100644 (file)
 #define TEST_NO_MAIN
 #include "acutest.h"
 #include "config.h"
-#include <stdbool.h>
 #include "mutt/mutt.h"
 
 void test_mutt_buffer_alloc(void)
 {
-  // struct Buffer *mutt_buffer_alloc(size_t size);
+  // void mutt_buffer_alloc(struct Buffer *buf, size_t new_size);
 
-  size_t alloc_tests[] = { 0, 42, 1048576 };
+  {
+    mutt_buffer_alloc(NULL, 10);
+    TEST_CHECK_(1, "mutt_buffer_alloc(NULL, 10)");
+  }
+
+  {
+    struct Buffer buf = { 0 };
+    mutt_buffer_alloc(&buf, 10);
+    TEST_CHECK_(1, "mutt_buffer_alloc(buf, 10)");
+    mutt_buffer_dealloc(&buf);
+  }
 
-  for (size_t i = 0; i < mutt_array_size(alloc_tests); i++)
   {
-    struct Buffer *buf = NULL;
-    TEST_CASE_("%lu", alloc_tests[i]);
-    buf = mutt_buffer_alloc(alloc_tests[i]);
-    TEST_CHECK(buf != NULL);
-    mutt_buffer_free(&buf);
+    const int orig_size = 64;
+    static int sizes[] = { 0, 32, 64, 128 };
+
+    for (size_t i = 0; i < mutt_array_size(sizes); i++)
+    {
+      struct Buffer buf = { 0 };
+      mutt_buffer_alloc(&buf, orig_size);
+      TEST_CASE_("%d", sizes[i]);
+      mutt_buffer_alloc(&buf, sizes[i]);
+      TEST_CHECK(buf.dsize == MAX(orig_size, sizes[i]));
+      mutt_buffer_dealloc(&buf);
+    }
   }
 }
index ce2040d9250ace8588e4d29463507b258af75738..cb0eea4205fca172a2b9626154918c862d5cb3b6 100644 (file)
@@ -59,20 +59,20 @@ void test_mutt_buffer_concat_path(void)
       TEST_CASE_("DIR: '%s'  FILE: '%s'", NONULL(concat_test[i][0]),
                  NONULL(concat_test[i][1]));
       {
-        struct Buffer *buf = mutt_buffer_new();
-        mutt_buffer_concat_path(buf, concat_test[i][0], concat_test[i][1]);
+        struct Buffer buf = { 0 };
+        mutt_buffer_concat_path(&buf, concat_test[i][0], concat_test[i][1]);
         if (concat_test[i][2])
         {
-          TEST_CHECK(strcmp(mutt_b2s(buf), concat_test[i][2]) == 0);
+          TEST_CHECK(strcmp(mutt_b2s(&buf), concat_test[i][2]) == 0);
         }
         else
         {
-          if (!TEST_CHECK(strlen(mutt_b2s(buf)) == 0))
+          if (!TEST_CHECK(strlen(mutt_b2s(&buf)) == 0))
           {
-            TEST_MSG("len = %ld", strlen(mutt_b2s(buf)));
+            TEST_MSG("len = %ld", strlen(mutt_b2s(&buf)));
           }
         }
-        mutt_buffer_free(&buf);
+        mutt_buffer_dealloc(&buf);
       }
 
       {
index 4ee26a8dfcf9bbe4567034da6d757e509a419b98..d29030fea85b80cfed6c7b0ce0626910f06c0bf8 100644 (file)
@@ -35,10 +35,9 @@ void test_mutt_buffer_fix_dptr(void)
   }
 
   {
-    struct Buffer *buf = mutt_buffer_new();
-    mutt_buffer_fix_dptr(buf);
-    TEST_CHECK(mutt_buffer_len(buf) == 0);
-    mutt_buffer_free(&buf);
+    struct Buffer buf = { 0 };
+    mutt_buffer_fix_dptr(&buf);
+    TEST_CHECK(mutt_buffer_len(&buf) == 0);
   }
 
   {
diff --git a/test/buffer/mutt_buffer_increase_size.c b/test/buffer/mutt_buffer_increase_size.c
deleted file mode 100644 (file)
index 45435d1..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * @file
- * Test code for mutt_buffer_increase_size()
- *
- * @authors
- * Copyright (C) 2019 Richard Russon <rich@flatcap.org>
- *
- * @copyright
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 2 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#define TEST_NO_MAIN
-#include "acutest.h"
-#include "config.h"
-#include "mutt/mutt.h"
-
-void test_mutt_buffer_increase_size(void)
-{
-  // void mutt_buffer_increase_size(struct Buffer *buf, size_t new_size);
-
-  {
-    mutt_buffer_increase_size(NULL, 10);
-    TEST_CHECK_(1, "mutt_buffer_increase_size(NULL, 10)");
-  }
-
-  {
-    struct Buffer *buf = mutt_buffer_new();
-    mutt_buffer_increase_size(buf, 10);
-    TEST_CHECK_(1, "mutt_buffer_increase_size(buf, 10)");
-    mutt_buffer_free(&buf);
-  }
-
-  {
-    const int orig_size = 64;
-    static int sizes[] = { 0, 32, 64, 128 };
-
-    for (size_t i = 0; i < mutt_array_size(sizes); i++)
-    {
-      struct Buffer *buf = mutt_buffer_alloc(orig_size);
-      TEST_CASE_("%d", sizes[i]);
-      mutt_buffer_increase_size(buf, sizes[i]);
-      TEST_CHECK(buf->dsize == MAX(orig_size, sizes[i]));
-      mutt_buffer_free(&buf);
-    }
-  }
-}
index c8355d86fdd00bedc522094775b36b3829422249..68ca4b24765679eac2b4c96165366dc6cd1cabbd 100644 (file)
@@ -34,8 +34,7 @@ void test_mutt_buffer_init(void)
   }
 
   {
-    struct Buffer *buf = mutt_buffer_new();
-    TEST_CHECK(mutt_buffer_init(buf) != NULL);
-    mutt_buffer_free(&buf);
+    struct Buffer buf = { 0 };
+    TEST_CHECK(mutt_buffer_init(&buf) != NULL);
   }
 }
index deeff12bbba41b947c2dc05ff46ac1dfcec2f39c..2e8f6c3875a97eee3d77a6836b9e15cbc13dd087 100644 (file)
@@ -34,9 +34,8 @@ void test_mutt_buffer_is_empty(void)
   }
 
   {
-    struct Buffer *buf = mutt_buffer_new();
-    TEST_CHECK(mutt_buffer_is_empty(buf));
-    mutt_buffer_free(&buf);
+    struct Buffer buf = { 0 };
+    TEST_CHECK(mutt_buffer_is_empty(&buf));
   }
 
   {
index e763c1cd9e861ee015478859176e1dc8092576df..c7dcdb8a76268f078a38f53d5f8e14cbf247ee56 100644 (file)
@@ -34,9 +34,8 @@ void test_mutt_buffer_len(void)
   }
 
   {
-    struct Buffer *buf = mutt_buffer_new();
-    TEST_CHECK(mutt_buffer_len(buf) == 0);
-    mutt_buffer_free(&buf);
+    struct Buffer buf = { 0 };
+    TEST_CHECK(mutt_buffer_len(&buf) == 0);
   }
 
   {
index ed8de9ee63909b451bad5db3626ee5d6c788eeea..b09bf90ef9df8d51cdf5dab061fb6aefcaf033df 100644 (file)
@@ -42,29 +42,29 @@ void test_mutt_buffer_printf(void)
 
   {
     TEST_CASE("Empty");
-    struct Buffer *buf = mutt_buffer_new();
-    TEST_CHECK(mutt_buffer_printf(buf, "") == 0);
-    TEST_CHECK(strlen(mutt_b2s(buf)) == 0);
-    mutt_buffer_free(&buf);
+    struct Buffer buf = { 0 };
+    TEST_CHECK(mutt_buffer_printf(&buf, "") == 0);
+    TEST_CHECK(strlen(mutt_b2s(&buf)) == 0);
+    mutt_buffer_dealloc(&buf);
   }
 
   {
     TEST_CASE("Static");
     const char *str = "apple";
-    struct Buffer *buf = mutt_buffer_new();
-    TEST_CHECK(mutt_buffer_printf(buf, str) == 5);
-    TEST_CHECK(strcmp(mutt_b2s(buf), str) == 0);
-    mutt_buffer_free(&buf);
+    struct Buffer buf = { 0 };
+    TEST_CHECK(mutt_buffer_printf(&buf, str) == 5);
+    TEST_CHECK(strcmp(mutt_b2s(&buf), str) == 0);
+    mutt_buffer_dealloc(&buf);
   }
 
   {
     TEST_CASE("Varargs");
     const char *str = "apple";
     const char *result = "app 1234567 3.1416";
-    struct Buffer *buf = mutt_buffer_new();
-    TEST_CHECK(mutt_buffer_printf(buf, "%.3s %ld %3.4f", str, 1234567, 3.141592654) == 18);
-    TEST_CHECK(strcmp(mutt_b2s(buf), result) == 0);
-    mutt_buffer_free(&buf);
+    struct Buffer buf = { 0 };
+    TEST_CHECK(mutt_buffer_printf(&buf, "%.3s %ld %3.4f", str, 1234567, 3.141592654) == 18);
+    TEST_CHECK(strcmp(mutt_b2s(&buf), result) == 0);
+    mutt_buffer_dealloc(&buf);
   }
 
   TEST_CASE("printf to a non-empty Buffer");
index cdce3391a06afbd96e8cea30b1194872eb2e6be0..d0989c85817d9b86a5d6cca2213593ecf5131d14 100644 (file)
@@ -35,10 +35,9 @@ void test_mutt_buffer_reset(void)
   }
 
   {
-    struct Buffer *buf = mutt_buffer_new();
-    mutt_buffer_reset(buf);
+    struct Buffer buf = { 0 };
+    mutt_buffer_reset(&buf);
     TEST_CHECK_(1, "mutt_buffer_reset(buf)");
-    mutt_buffer_free(&buf);
   }
 
   {
index 06a720f5e3511321ffae5d13ab62e2b4d07f21f9..9f85e4d5a478bea788dad9d92ea31384ce148bc6 100644 (file)
@@ -44,19 +44,19 @@ void test_mutt_buffer_strcpy(void)
 
   {
     TEST_CASE("Empty");
-    struct Buffer *buf = mutt_buffer_new();
-    mutt_buffer_strcpy(buf, "");
-    TEST_CHECK(strcmp(mutt_b2s(buf), "") == 0);
-    mutt_buffer_free(&buf);
+    struct Buffer buf = { 0 };
+    mutt_buffer_strcpy(&buf, "");
+    TEST_CHECK(strcmp(mutt_b2s(&buf), "") == 0);
+    mutt_buffer_dealloc(&buf);
   }
 
   {
     TEST_CASE("String");
     const char *str = "test";
-    struct Buffer *buf = mutt_buffer_new();
-    mutt_buffer_strcpy(buf, str);
-    TEST_CHECK(strcmp(mutt_b2s(buf), str) == 0);
-    mutt_buffer_free(&buf);
+    struct Buffer buf = { 0 };
+    mutt_buffer_strcpy(&buf, str);
+    TEST_CHECK(strcmp(mutt_b2s(&buf), str) == 0);
+    mutt_buffer_dealloc(&buf);
   }
 
   TEST_CASE("Overwrite a non-empty Buffer");
index b254ccc1b33f55c0d81831d038f548ac0689f13c..f78d37f5ea888526399f8ecb981712c359224949 100644 (file)
@@ -50,11 +50,11 @@ void test_mutt_buffer_strcpy_n(void)
     for (size_t i = 0; i < mutt_array_size(sizes); i++)
     {
       TEST_CASE_("%ld", sizes[i]);
-      struct Buffer *buf = mutt_buffer_new();
-      mutt_buffer_strcpy_n(buf, str, sizes[i]);
-      TEST_CHECK(strlen(mutt_b2s(buf)) == MIN(len, sizes[i]));
-      TEST_CHECK(strncmp(mutt_b2s(buf), str, sizes[i]) == 0);
-      mutt_buffer_free(&buf);
+      struct Buffer buf = { 0 };
+      mutt_buffer_strcpy_n(&buf, str, sizes[i]);
+      TEST_CHECK(strlen(mutt_b2s(&buf)) == MIN(len, sizes[i]));
+      TEST_CHECK(strncmp(mutt_b2s(&buf), str, sizes[i]) == 0);
+      mutt_buffer_dealloc(&buf);
     }
   }
 
index 3dde846ae8d672256d7acc2bf387aeffc7fec915..8320da2a611ee55b9bd8b50ff7f72deeb0e28cf6 100644 (file)
@@ -98,20 +98,21 @@ bool test_pretty_var(void)
   }
 
   {
-    struct Buffer *buf = mutt_buffer_alloc(64);
-    if (!TEST_CHECK(pretty_var("apple", buf) > 0))
+    struct Buffer buf = { 0 };
+    mutt_buffer_alloc(&buf, 64);
+    if (!TEST_CHECK(pretty_var("apple", &buf) > 0))
     {
-      mutt_buffer_free(&buf);
+      mutt_buffer_dealloc(&buf);
       return false;
     }
 
-    if (!TEST_CHECK(mutt_str_strcmp("\"apple\"", mutt_b2s(buf)) == 0))
+    if (!TEST_CHECK(mutt_str_strcmp("\"apple\"", mutt_b2s(&buf)) == 0))
     {
-      mutt_buffer_free(&buf);
+      mutt_buffer_dealloc(&buf);
       return false;
     }
 
-    mutt_buffer_free(&buf);
+    mutt_buffer_dealloc(&buf);
   }
 
   return true;
@@ -136,20 +137,21 @@ bool test_escape_string(void)
     const char *before = "apple\nbanana\rcherry\tdamson\\endive\"fig'grape";
     const char *after =
         "apple\\nbanana\\rcherry\\tdamson\\\\endive\\\"fig'grape";
-    struct Buffer *buf = mutt_buffer_alloc(256);
-    if (!TEST_CHECK(escape_string(buf, before) > 0))
+    struct Buffer buf = { 0 };
+    mutt_buffer_alloc(&buf, 256);
+    if (!TEST_CHECK(escape_string(&buf, before) > 0))
     {
-      mutt_buffer_free(&buf);
+      mutt_buffer_dealloc(&buf);
       return false;
     }
 
-    if (!TEST_CHECK(mutt_str_strcmp(mutt_b2s(buf), after) == 0))
+    if (!TEST_CHECK(mutt_str_strcmp(mutt_b2s(&buf), after) == 0))
     {
-      mutt_buffer_free(&buf);
+      mutt_buffer_dealloc(&buf);
       return false;
     }
 
-    mutt_buffer_free(&buf);
+    mutt_buffer_dealloc(&buf);
   }
 
   return true;
index 06fab4f903e52d9dc938b4b90648a4c46fa54917..a7d169c9ef38f8a4057f923a3ad002845f17b756 100644 (file)
@@ -42,10 +42,11 @@ void test_mutt_buffer_file_expand_fmt_quote(void)
   }
 
   {
-    struct Buffer *buf = mutt_buffer_alloc(32);
-    mutt_buffer_file_expand_fmt_quote(buf, "apple", NULL);
+    struct Buffer buf = { 0 };
+    mutt_buffer_alloc(&buf, 32);
+    mutt_buffer_file_expand_fmt_quote(&buf, "apple", NULL);
     TEST_CHECK_(1, "mutt_buffer_file_expand_fmt_quote(&buf, \"apple\", NULL)");
-    mutt_buffer_free(&buf);
+    mutt_buffer_dealloc(&buf);
   }
 
   mutt_buffer_pool_free();
index 5e66fe25c35f7ebc429ebacd5f2270b5d516c7c3..6eab1010abf2d4a1e113d0e8e6e4be22b0a27a92 100644 (file)
@@ -72,7 +72,6 @@
   NEOMUTT_TEST_ITEM(test_mutt_buffer_fix_dptr)                                 \
   NEOMUTT_TEST_ITEM(test_mutt_buffer_free)                                     \
   NEOMUTT_TEST_ITEM(test_mutt_buffer_from)                                     \
-  NEOMUTT_TEST_ITEM(test_mutt_buffer_increase_size)                            \
   NEOMUTT_TEST_ITEM(test_mutt_buffer_init)                                     \
   NEOMUTT_TEST_ITEM(test_mutt_buffer_is_empty)                                 \
   NEOMUTT_TEST_ITEM(test_mutt_buffer_len)                                      \
index dbf35d9f97ba179c49f713a6164c7de9f619cf43..2eb63749affca331505ab887d9db8b43e9f9d797 100644 (file)
@@ -35,9 +35,9 @@ void test_mutt_path_getcwd(void)
   }
 
   {
-    struct Buffer *buf = mutt_buffer_new();
-    mutt_path_getcwd(buf);
-    TEST_CHECK(buf->data[0] == '/');
-    mutt_buffer_free(&buf);
+    struct Buffer buf = { 0 };
+    mutt_path_getcwd(&buf);
+    TEST_CHECK(buf.data[0] == '/');
+    mutt_buffer_dealloc(&buf);
   }
 }
index 7e879d4b9fdc7ab0064360b96c70543a6129678b..6e2d20ef7a2c220c29b007590ec5a4f2c67f1336 100644 (file)
@@ -172,13 +172,14 @@ static int cmp_pattern(struct PatternList *p1, struct PatternList *p2)
 
 void test_mutt_pattern_comp(void)
 {
-  struct Buffer *err = mutt_buffer_alloc(1024);
+  struct Buffer err = { 0 };
+  mutt_buffer_alloc(&err, 1024);
 
   { /* empty */
     char *s = "";
 
-    mutt_buffer_reset(err);
-    struct PatternList *pat = mutt_pattern_comp(s, 0, err);
+    mutt_buffer_reset(&err);
+    struct PatternList *pat = mutt_pattern_comp(s, 0, &err);
 
     if (!TEST_CHECK(!pat))
     {
@@ -187,18 +188,18 @@ void test_mutt_pattern_comp(void)
     }
 
     char *msg = "empty pattern";
-    if (!TEST_CHECK(!strcmp(err->data, msg)))
+    if (!TEST_CHECK(!strcmp(err.data, msg)))
     {
       TEST_MSG("Expected: %s", msg);
-      TEST_MSG("Actual  : %s", err->data);
+      TEST_MSG("Actual  : %s", err.data);
     }
   }
 
   { /* invalid */
     char *s = "x";
 
-    mutt_buffer_reset(err);
-    struct PatternList *pat = mutt_pattern_comp(s, 0, err);
+    mutt_buffer_reset(&err);
+    struct PatternList *pat = mutt_pattern_comp(s, 0, &err);
 
     if (!TEST_CHECK(!pat))
     {
@@ -207,18 +208,18 @@ void test_mutt_pattern_comp(void)
     }
 
     char *msg = "error in pattern at: x";
-    if (!TEST_CHECK(!strcmp(err->data, msg)))
+    if (!TEST_CHECK(!strcmp(err.data, msg)))
     {
       TEST_MSG("Expected: %s", msg);
-      TEST_MSG("Actual  : %s", err->data);
+      TEST_MSG("Actual  : %s", err.data);
     }
   }
 
   { /* missing parameter */
     char *s = "=s";
 
-    mutt_buffer_reset(err);
-    struct PatternList *pat = mutt_pattern_comp(s, 0, err);
+    mutt_buffer_reset(&err);
+    struct PatternList *pat = mutt_pattern_comp(s, 0, &err);
 
     if (!TEST_CHECK(!pat))
     {
@@ -227,18 +228,18 @@ void test_mutt_pattern_comp(void)
     }
 
     char *msg = "missing parameter";
-    if (!TEST_CHECK(!strcmp(err->data, msg)))
+    if (!TEST_CHECK(!strcmp(err.data, msg)))
     {
       TEST_MSG("Expected: %s", msg);
-      TEST_MSG("Actual  : %s", err->data);
+      TEST_MSG("Actual  : %s", err.data);
     }
   }
 
   { /* error in pattern */
     char *s = "| =s foo";
 
-    mutt_buffer_reset(err);
-    struct PatternList *pat = mutt_pattern_comp(s, 0, err);
+    mutt_buffer_reset(&err);
+    struct PatternList *pat = mutt_pattern_comp(s, 0, &err);
 
     if (!TEST_CHECK(!pat))
     {
@@ -247,18 +248,18 @@ void test_mutt_pattern_comp(void)
     }
 
     char *msg = "error in pattern at: | =s foo";
-    if (!TEST_CHECK(!strcmp(err->data, msg)))
+    if (!TEST_CHECK(!strcmp(err.data, msg)))
     {
       TEST_MSG("Expected: %s", msg);
-      TEST_MSG("Actual  : %s", err->data);
+      TEST_MSG("Actual  : %s", err.data);
     }
   }
 
   {
     char *s = "=s foobar";
 
-    mutt_buffer_reset(err);
-    struct PatternList *pat = mutt_pattern_comp(s, 0, err);
+    mutt_buffer_reset(&err);
+    struct PatternList *pat = mutt_pattern_comp(s, 0, &err);
 
     if (!TEST_CHECK(pat != NULL))
     {
@@ -291,10 +292,10 @@ void test_mutt_pattern_comp(void)
     }
 
     char *msg = "";
-    if (!TEST_CHECK(!strcmp(err->data, msg)))
+    if (!TEST_CHECK(!strcmp(err.data, msg)))
     {
       TEST_MSG("Expected: %s", msg);
-      TEST_MSG("Actual  : %s", err->data);
+      TEST_MSG("Actual  : %s", err.data);
     }
 
     mutt_pattern_free(&pat);
@@ -303,8 +304,8 @@ void test_mutt_pattern_comp(void)
   {
     char *s = "! =s foobar";
 
-    mutt_buffer_reset(err);
-    struct PatternList *pat = mutt_pattern_comp(s, 0, err);
+    mutt_buffer_reset(&err);
+    struct PatternList *pat = mutt_pattern_comp(s, 0, &err);
 
     if (!TEST_CHECK(pat != NULL))
     {
@@ -338,10 +339,10 @@ void test_mutt_pattern_comp(void)
     }
 
     char *msg = "";
-    if (!TEST_CHECK(!strcmp(err->data, msg)))
+    if (!TEST_CHECK(!strcmp(err.data, msg)))
     {
       TEST_MSG("Expected: %s", msg);
-      TEST_MSG("Actual  : %s", err->data);
+      TEST_MSG("Actual  : %s", err.data);
     }
 
     mutt_pattern_free(&pat);
@@ -350,8 +351,8 @@ void test_mutt_pattern_comp(void)
   {
     char *s = "=s foo =s bar";
 
-    mutt_buffer_reset(err);
-    struct PatternList *pat = mutt_pattern_comp(s, 0, err);
+    mutt_buffer_reset(&err);
+    struct PatternList *pat = mutt_pattern_comp(s, 0, &err);
 
     if (!TEST_CHECK(pat != NULL))
     {
@@ -417,10 +418,10 @@ void test_mutt_pattern_comp(void)
     }
 
     char *msg = "";
-    if (!TEST_CHECK(!strcmp(err->data, msg)))
+    if (!TEST_CHECK(!strcmp(err.data, msg)))
     {
       TEST_MSG("Expected: %s", msg);
-      TEST_MSG("Actual  : %s", err->data);
+      TEST_MSG("Actual  : %s", err.data);
     }
 
     mutt_pattern_free(&pat);
@@ -429,8 +430,8 @@ void test_mutt_pattern_comp(void)
   {
     char *s = "(=s foo =s bar)";
 
-    mutt_buffer_reset(err);
-    struct PatternList *pat = mutt_pattern_comp(s, 0, err);
+    mutt_buffer_reset(&err);
+    struct PatternList *pat = mutt_pattern_comp(s, 0, &err);
 
     if (!TEST_CHECK(pat != NULL))
     {
@@ -496,10 +497,10 @@ void test_mutt_pattern_comp(void)
     }
 
     char *msg = "";
-    if (!TEST_CHECK(!strcmp(err->data, msg)))
+    if (!TEST_CHECK(!strcmp(err.data, msg)))
     {
       TEST_MSG("Expected: %s", msg);
-      TEST_MSG("Actual  : %s", err->data);
+      TEST_MSG("Actual  : %s", err.data);
     }
 
     mutt_pattern_free(&pat);
@@ -508,8 +509,8 @@ void test_mutt_pattern_comp(void)
   {
     char *s = "! (=s foo =s bar)";
 
-    mutt_buffer_reset(err);
-    struct PatternList *pat = mutt_pattern_comp(s, 0, err);
+    mutt_buffer_reset(&err);
+    struct PatternList *pat = mutt_pattern_comp(s, 0, &err);
 
     if (!TEST_CHECK(pat != NULL))
     {
@@ -575,10 +576,10 @@ void test_mutt_pattern_comp(void)
     }
 
     char *msg = "";
-    if (!TEST_CHECK(!strcmp(err->data, msg)))
+    if (!TEST_CHECK(!strcmp(err.data, msg)))
     {
       TEST_MSG("Expected: %s", msg);
-      TEST_MSG("Actual  : %s", err->data);
+      TEST_MSG("Actual  : %s", err.data);
     }
 
     mutt_pattern_free(&pat);
@@ -587,8 +588,8 @@ void test_mutt_pattern_comp(void)
   {
     char *s = "=s foo =s bar =s quux";
 
-    mutt_buffer_reset(err);
-    struct PatternList *pat = mutt_pattern_comp(s, 0, err);
+    mutt_buffer_reset(&err);
+    struct PatternList *pat = mutt_pattern_comp(s, 0, &err);
 
     if (!TEST_CHECK(pat != NULL))
     {
@@ -666,10 +667,10 @@ void test_mutt_pattern_comp(void)
     }
 
     char *msg = "";
-    if (!TEST_CHECK(!strcmp(err->data, msg)))
+    if (!TEST_CHECK(!strcmp(err.data, msg)))
     {
       TEST_MSG("Expected: %s", msg);
-      TEST_MSG("Actual  : %s", err->data);
+      TEST_MSG("Actual  : %s", err.data);
     }
 
     mutt_pattern_free(&pat);
@@ -678,8 +679,8 @@ void test_mutt_pattern_comp(void)
   {
     char *s = "!(=s foo|=s bar) =s quux";
 
-    mutt_buffer_reset(err);
-    struct PatternList *pat = mutt_pattern_comp(s, 0, err);
+    mutt_buffer_reset(&err);
+    struct PatternList *pat = mutt_pattern_comp(s, 0, &err);
 
     if (!TEST_CHECK(pat != NULL))
     {
@@ -773,14 +774,14 @@ void test_mutt_pattern_comp(void)
     }
 
     char *msg = "";
-    if (!TEST_CHECK(!strcmp(err->data, msg)))
+    if (!TEST_CHECK(!strcmp(err.data, msg)))
     {
       TEST_MSG("Expected: %s", msg);
-      TEST_MSG("Actual  : %s", err->data);
+      TEST_MSG("Actual  : %s", err.data);
     }
 
     mutt_pattern_free(&pat);
   }
 
-  mutt_buffer_free(&err);
+  mutt_buffer_dealloc(&err);
 }
index 59d031f25a36b457dde64dfe124a35a0011ff161..1827ec74be91457165243d16cc2b5754b7dead3c 100644 (file)
@@ -9,9 +9,9 @@ static bool test_simple_cases(void)
 {
   log_line(__func__);
 
-  struct Buffer *buf = mutt_buffer_new();
+  struct Buffer buf = { 0 };
   { /* handle edge cases */
-    struct Regex *rx = regex_new("hello bob", 0, buf);
+    struct Regex *rx = regex_new("hello bob", 0, &buf);
 
     const bool failed = !TEST_CHECK(mutt_regex_match(NULL, NULL) == false) ||
                         !TEST_CHECK(mutt_regex_match(NULL, "bob the string") == false) ||
@@ -23,7 +23,7 @@ static bool test_simple_cases(void)
   }
 
   { /* handle normal cases */
-    struct Regex *rx = regex_new("hell", 0, buf);
+    struct Regex *rx = regex_new("hell", 0, &buf);
 
     const bool failed =
         !TEST_CHECK(mutt_regex_match(rx, "hello there")) ||
@@ -37,7 +37,7 @@ static bool test_simple_cases(void)
 
   { /* test more elaborate regex */
     const char *input = "bob bob bob mary bob jonny bob jon jon joe bob";
-    struct Regex *rx = regex_new("bob", 0, buf);
+    struct Regex *rx = regex_new("bob", 0, &buf);
 
     const bool result = mutt_regex_capture(rx, input, 0, NULL);
     const bool failed = !TEST_CHECK(result);
@@ -49,7 +49,7 @@ static bool test_simple_cases(void)
 
   { /* test passing simple flags */
     const char *input = "BOB";
-    struct Regex *rx = regex_new("bob", 0, buf);
+    struct Regex *rx = regex_new("bob", 0, &buf);
     const bool failed = !TEST_CHECK(mutt_regex_capture(rx, input, 0, 0));
     regex_free(&rx);
 
@@ -57,7 +57,7 @@ static bool test_simple_cases(void)
       return false;
   }
 
-  mutt_buffer_free(&buf);
+  mutt_buffer_dealloc(&buf);
   return true;
 }
 
@@ -71,12 +71,12 @@ static bool test_old_implementation(void)
   const char *bob_line = "definitely bob haha";
   const char *not_bob_line = "john dave marty nothing else here";
 
-  struct Buffer *buf = mutt_buffer_new();
+  struct Buffer buf = { 0 };
   {
     // from: if (regexec(C_PgpGoodSign->regex, bob_line, 0, NULL, 0) == 0)
     //   to: if (mutt_regex_match(C_PgpGoodSign, bob_line))
 
-    struct Regex *rx = regex_new("bob", 0, buf);
+    struct Regex *rx = regex_new("bob", 0, &buf);
     const bool old = regexec(rx->regex, bob_line, 0, NULL, 0) == 0;
     const bool new = mutt_regex_match(rx, bob_line);
     const bool failed = !TEST_CHECK(old == new);
@@ -92,7 +92,7 @@ static bool test_old_implementation(void)
 
     const int nmatch = 1;
     regmatch_t pmatch_1[nmatch], pmatch_2[nmatch];
-    struct Regex *rx = regex_new("bob", 0, buf);
+    struct Regex *rx = regex_new("bob", 0, &buf);
     const bool old = regexec(rx->regex, bob_line, nmatch, pmatch_1, 0) == 0;
     const bool new = mutt_regex_capture(rx, bob_line, 1, pmatch_2);
     const bool failed_common_behavior = !TEST_CHECK(old == new);
@@ -110,7 +110,7 @@ static bool test_old_implementation(void)
     const int nmatch = 1;
     regmatch_t pmatch_1[nmatch], pmatch_2[nmatch];
 
-    struct Regex *rx = regex_new("bob", 0, buf);
+    struct Regex *rx = regex_new("bob", 0, &buf);
     const bool old = rx && rx->regex &&
                      (regexec(rx->regex, bob_line, nmatch, pmatch_1, 0) == 0);
     const bool new = mutt_regex_capture(rx, bob_line, 1, pmatch_2);
@@ -132,7 +132,7 @@ static bool test_old_implementation(void)
     //          tmp->regex.pat_not))
     //   to: if ((tmp->type & hook) && mutt_regex_match(&tmp->regex, match))
 
-    struct Regex *rx = regex_new("!bob", DT_REGEX_ALLOW_NOT, buf);
+    struct Regex *rx = regex_new("!bob", DT_REGEX_ALLOW_NOT, &buf);
     const bool old =
         (regexec(rx->regex, not_bob_line, 0, NULL, DT_REGEX_ALLOW_NOT) == 0) ^ rx->pat_not;
     const bool new = mutt_regex_match(rx, not_bob_line);
@@ -154,7 +154,7 @@ static bool test_old_implementation(void)
     //       ^ C_Mask->pat_not))
     // to: if(mutt_regex_match(C_Mask, de->d_name))
 
-    struct Regex *rx = regex_new("!bob", DT_REGEX_ALLOW_NOT, buf);
+    struct Regex *rx = regex_new("!bob", DT_REGEX_ALLOW_NOT, &buf);
     const bool old = rx && rx->regex &&
                      !((regexec(rx->regex, not_bob_line, 0, NULL, 0) == 0) ^ rx->pat_not);
     const bool new = mutt_regex_match(rx, bob_line);
@@ -169,7 +169,7 @@ static bool test_old_implementation(void)
     // from: if (C_Mask && C_Mask->regex &&
     //          !((regexec(C_Mask->regex, mdata->group, 0, NULL, 0) == 0) ^ C_Mask->pat_not))
     //   to: if (!mutt_regex_match(C_Mask, mdata->group))
-    struct Regex *rx = regex_new("!bob", DT_REGEX_ALLOW_NOT, buf);
+    struct Regex *rx = regex_new("!bob", DT_REGEX_ALLOW_NOT, &buf);
     const bool old = (rx && rx->regex) &&
                      !((regexec(rx->regex, line, 0, NULL, 0) == 0) ^ rx->pat_not);
     const bool new = !mutt_regex_match(rx, line);
@@ -184,7 +184,7 @@ static bool test_old_implementation(void)
     // if ((regexec(hook->regex.regex, url, 0, NULL, 0) == 0) ^ hook->regex.pat_not)
     // if (mutt_regex_match(&hook->regex, url))
 
-    struct Regex *rx = regex_new("bob", 0, buf);
+    struct Regex *rx = regex_new("bob", 0, &buf);
     const bool old = (regexec(rx->regex, bob_line, 0, NULL, 0) == 0) ^ rx->pat_not;
     const bool new = mutt_regex_match(rx, bob_line);
     regex_free(&rx);
@@ -194,7 +194,7 @@ static bool test_old_implementation(void)
       return false;
   }
 
-  mutt_buffer_free(&buf);
+  mutt_buffer_dealloc(&buf);
   return true;
 }