make charset_canonicalize set the answer to "us-ascii" if s is NULL.
[apps/madmutt.git] / charset.c
index cd672b5..90a7307 100644 (file)
--- a/charset.c
+++ b/charset.c
@@ -98,6 +98,11 @@ void charset_canonicalize(char *dest, ssize_t dlen, const char *name)
     const char *p;
     int i = 0;
 
+    if (!name) {
+        m_strcpy(dest, dlen, "us-ascii");
+        return;
+    }
+
     // canonize name: only keep a-z0-9 and dots, put into lowercase
     for (p = name; *p && *p != ':' && i < ssizeof(scratch) - 1; p++) {
         if (isalnum(*p) || *p== '.') {
@@ -129,25 +134,18 @@ const char *charset_getfirst(const char *charset)
     return fcharset;
 }
 
-static int mutt_chscmp(const char *s, const char *chs)
-{
-    char buffer[SHORT_STRING];
-
-    if (!s)
-        return 0;
-
-    charset_canonicalize(buffer, sizeof(buffer), s);
-    return !strcmp(buffer, chs);
-}
-
 int charset_is_utf8(const char *s)
 {
-    return mutt_chscmp(s, "utf-8");
+    char buf[SHORT_STRING];
+    charset_canonicalize(buf, sizeof(buf), s);
+    return !strcmp(buf, "utf-8");
 }
 
 int charset_is_us_ascii(const char *s)
 {
-    return mutt_chscmp(s, "us-ascii");
+    char buf[SHORT_STRING];
+    charset_canonicalize(buf, sizeof(buf), s);
+    return !strcmp(buf, "us-ascii");
 }