]> granicus.if.org Git - mutt/commitdiff
Convert rfc1524_mailcap_lookup() to use buffer pool for path.
authorKevin McCarthy <kevin@8t8.us>
Wed, 23 Oct 2019 11:01:17 +0000 (19:01 +0800)
committerKevin McCarthy <kevin@8t8.us>
Wed, 23 Oct 2019 11:01:17 +0000 (19:01 +0800)
Adjust the rfc1524_mailcap_parse() and get_field_text() filename and
type parameters to be const.

Note that the sizeof(type) needs to be passed to
rfc1524_mailcap_lookup().  I'll fix that next.

rfc1524.c

index 228c5671aaf8dddfd192dc8d6ab7a2263b3e6df5..6597df2bb0bc7fbf947b24ba166f39dd707f9953 100644 (file)
--- a/rfc1524.c
+++ b/rfc1524.c
@@ -176,7 +176,7 @@ static char *get_field (char *s)
 }
 
 static int get_field_text (char *field, char **entry,
-                          char *type, char *filename, int line)
+                          const char *type, const char *filename, int line)
 {
   field = mutt_skip_whitespace (field);
   if (*field == '=')
@@ -198,8 +198,8 @@ static int get_field_text (char *field, char **entry,
 }
 
 static int rfc1524_mailcap_parse (BODY *a,
-                                 char *filename,
-                                 char *type,
+                                 const char *filename,
+                                 const char *type,
                                  rfc1524_entry *entry,
                                  int opt)
 {
@@ -422,8 +422,7 @@ void rfc1524_free_entry(rfc1524_entry **entry)
  */
 int rfc1524_mailcap_lookup (BODY *a, char *type, rfc1524_entry *entry, int opt)
 {
-  char path[_POSIX_PATH_MAX];
-  int x;
+  BUFFER *path = NULL;
   int found = FALSE;
   char *curr = MailcapPath;
 
@@ -439,29 +438,33 @@ int rfc1524_mailcap_lookup (BODY *a, char *type, rfc1524_entry *entry, int opt)
     return 0;
   }
 
+  /* FIXME: sizeof type should be passed to rfc1524_mailcap_lookup() */
   mutt_check_lookup_list (a, type, SHORT_STRING);
 
+  path = mutt_buffer_pool_get ();
+
   while (!found && *curr)
   {
-    x = 0;
-    while (*curr && *curr != ':' && x < sizeof (path) - 1)
+    mutt_buffer_clear (path);
+    while (*curr && *curr != ':')
     {
-      path[x++] = *curr;
+      mutt_buffer_addch (path, *curr);
       curr++;
     }
     if (*curr)
       curr++;
 
-    if (!x)
+    if (!mutt_buffer_len (path))
       continue;
 
-    path[x] = '\0';
-    mutt_expand_path (path, sizeof (path));
+    mutt_buffer_expand_path (path);
 
-    dprint(2,(debugfile,"Checking mailcap file: %s\n",path));
-    found = rfc1524_mailcap_parse (a, path, type, entry, opt);
+    dprint(2,(debugfile,"Checking mailcap file: %s\n",mutt_b2s (path)));
+    found = rfc1524_mailcap_parse (a, mutt_b2s (path), type, entry, opt);
   }
 
+  mutt_buffer_pool_release (&path);
+
   if (entry && !found)
     mutt_error (_("mailcap entry for type %s not found"), type);