warning fixes
[apps/madmutt.git] / imap / utf7.c
index 690182b..95e8fd6 100644 (file)
@@ -1,19 +1,10 @@
 /*
+ * Copyright notice from original mutt:
  * Copyright (C) 2000 Edmund Grimley Evans <edmundo@rano.org>
- * 
- *     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, write to the Free Software
- *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *
+ * This file is part of mutt-ng, see http://www.muttng.org/.
+ * It's licensed under the GNU General Public License,
+ * please see the file GPL in the top level source directory.
  */
 
 #if HAVE_CONFIG_H
@@ -24,6 +15,8 @@
 #include "charset.h"
 #include "imap_private.h"
 
+#include "lib/mem.h"
+
 static int Index_64[128] = {
   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
@@ -59,7 +52,7 @@ static char *utf7_to_utf8 (const char *u7, size_t u7len, char **u8,
   char *buf, *p;
   int b, ch, k;
 
-  p = buf = safe_malloc (u7len + u7len / 8 + 1);
+  p = buf = mem_malloc (u7len + u7len / 8 + 1);
 
   for (; u7len; u7++, u7len--) {
     if (*u7 == '&') {
@@ -120,13 +113,13 @@ static char *utf7_to_utf8 (const char *u7, size_t u7len, char **u8,
   if (u8len)
     *u8len = p - buf;
 
-  safe_realloc (&buf, p - buf);
+  mem_realloc (&buf, p - buf);
   if (u8)
     *u8 = buf;
   return buf;
 
 bail:
-  FREE (&buf);
+  mem_free (&buf);
   return 0;
 }
 
@@ -149,7 +142,7 @@ static char *utf8_to_utf7 (const char *u8, size_t u8len, char **u7,
    * In the worst case we convert 2 chars to 7 chars. For example:
    * "\x10&\x10&..." -> "&ABA-&-&ABA-&-...".
    */
-  p = buf = safe_malloc ((u8len / 2) * 7 + 6);
+  p = buf = mem_malloc ((u8len / 2) * 7 + 6);
 
   while (u8len) {
     unsigned char c = *u8;
@@ -213,7 +206,7 @@ static char *utf8_to_utf7 (const char *u8, size_t u8len, char **u7,
   }
 
   if (u8len) {
-    FREE (&buf);
+    mem_free (&buf);
     return 0;
   }
 
@@ -226,34 +219,37 @@ static char *utf8_to_utf7 (const char *u8, size_t u8len, char **u7,
   *p++ = '\0';
   if (u7len)
     *u7len = p - buf;
-  safe_realloc (&buf, p - buf);
+  mem_realloc (&buf, p - buf);
   if (u7)
     *u7 = buf;
   return buf;
 
 bail:
-  FREE (&buf);
+  mem_free (&buf);
   return 0;
 }
 
 void imap_utf7_encode (char **s)
 {
   if (Charset) {
-    char *t = safe_strdup (*s);
+    char *t = str_dup (*s);
 
-    if (!mutt_convert_string (&t, Charset, "UTF-8", 0))
-      utf8_to_utf7 (t, strlen (t), s, 0);
-    FREE (&t);
+    if (!mutt_convert_string (&t, Charset, "UTF-8", 0)) {
+      char *u7 = utf8_to_utf7 (t, strlen (t), NULL, 0);
+      mem_free (s);
+      *s = u7;
+    }
+    mem_free (&t);
   }
 }
 
 void imap_utf7_decode (char **s)
 {
   if (Charset) {
-    char *t = utf7_to_utf8 (*s, strlen (*s), 0, 0);
+    char *t = utf7_to_utf8 (*s, str_len (*s), 0, 0);
 
     if (t && !mutt_convert_string (&t, "UTF-8", Charset, 0)) {
-      FREE (s);
+      mem_free (s);
       *s = t;
     }
   }