]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/transcode.c
Changes to eliminate warnings from new Clang.
[thirdparty/cups.git] / cups / transcode.c
index 380807f950ccc1302ef82494c9628b556e976cc7..e0342ecdb54451e454a645a3885842f297cf0cb9 100644 (file)
@@ -1,26 +1,18 @@
 /*
  * "$Id$"
  *
- *   Transcoding support for CUPS.
+ * Transcoding support for CUPS.
  *
- *   Copyright 2007-2010 by Apple Inc.
- *   Copyright 1997-2007 by Easy Software Products.
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1997-2007 by Easy Software Products.
  *
- *   These coded instructions, statements, and computer programs are the
- *   property of Apple Inc. and are protected by Federal copyright
- *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
- *   which should have been included with this file.  If this file is
- *   file is missing or damaged, see the license at "http://www.cups.org/".
+ * These coded instructions, statements, and computer programs are the
+ * property of Apple Inc. and are protected by Federal copyright
+ * law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file.  If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
  *
- *   This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- *   _cupsCharmapFlush() - Flush all character set maps out of cache.
- *   cupsCharsetToUTF8() - Convert legacy character set to UTF-8.
- *   cupsUTF8ToCharset() - Convert UTF-8 to legacy character set.
- *   cupsUTF8ToUTF32()   - Convert UTF-8 to UTF-32.
- *   cupsUTF32ToUTF8()   - Convert UTF-32 to UTF-8.
+ * This file is subject to the Apple OS-Developed Software exception.
  */
 
 /*
@@ -98,8 +90,7 @@ cupsCharsetToUTF8(
   * Check for valid arguments...
   */
 
-  DEBUG_printf(("2cupsCharsetToUTF8(dest=%p, src=\"%s\", maxout=%d, encoding=%d)",
-               dest, src, maxout, encoding));
+  DEBUG_printf(("2cupsCharsetToUTF8(dest=%p, src=\"%s\", maxout=%d, encoding=%d)", (void *)dest, src, maxout, encoding));
 
   if (!dest || !src || maxout < 1)
   {
@@ -117,7 +108,7 @@ cupsCharsetToUTF8(
   if (encoding == CUPS_UTF8 || encoding <= CUPS_US_ASCII ||
       encoding >= CUPS_ENCODING_VBCS_END)
   {
-    strlcpy((char *)dest, src, maxout);
+    strlcpy((char *)dest, src, (size_t)maxout);
     return ((int)strlen((char *)dest));
   }
 
@@ -141,11 +132,11 @@ cupsCharsetToUTF8(
 
       if (ch & 128)
       {
-       *destptr++ = 0xc0 | (ch >> 6);
-       *destptr++ = 0x80 | (ch & 0x3f);
+       *destptr++ = (cups_utf8_t)(0xc0 | (ch >> 6));
+       *destptr++ = (cups_utf8_t)(0x80 | (ch & 0x3f));
       }
       else
-       *destptr++ = ch;
+       *destptr++ = (cups_utf8_t)ch;
     }
 
     *destptr = '\0';
@@ -162,11 +153,15 @@ cupsCharsetToUTF8(
 
   if (map_encoding != encoding)
   {
+    char       toset[1024];            /* Destination character set */
+
     _cupsCharmapFlush();
 
+    snprintf(toset, sizeof(toset), "%s//IGNORE", _cupsEncodingName(encoding));
+
+    map_encoding  = encoding;
     map_from_utf8 = iconv_open(_cupsEncodingName(encoding), "UTF-8");
-    map_to_utf8   = iconv_open("UTF-8", _cupsEncodingName(encoding));
-    map_encoding     = encoding;
+    map_to_utf8   = iconv_open("UTF-8", toset);
   }
 
   if (map_to_utf8 != (iconv_t)-1)
@@ -174,7 +169,7 @@ cupsCharsetToUTF8(
     char *altdestptr = (char *)dest;   /* Silence bogus GCC type-punned */
 
     srclen       = strlen(src);
-    outBytesLeft = maxout - 1;
+    outBytesLeft = (size_t)maxout - 1;
 
     iconv(map_to_utf8, (char **)&src, &srclen, &altdestptr, &outBytesLeft);
     *altdestptr = '\0';
@@ -234,7 +229,7 @@ cupsUTF8ToCharset(
   if (encoding == CUPS_UTF8 ||
       encoding >= CUPS_ENCODING_VBCS_END)
   {
-    strlcpy(dest, (char *)src, maxout);
+    strlcpy(dest, (char *)src, (size_t)maxout);
     return ((int)strlen(dest));
   }
 
@@ -262,7 +257,7 @@ cupsUTF8ToCharset(
        ch = ((ch & 0x1f) << 6) | (*src++ & 0x3f);
 
        if (ch < maxch)
-          *destptr++ = ch;
+          *destptr++ = (char)ch;
        else
           *destptr++ = '?';
       }
@@ -270,7 +265,7 @@ cupsUTF8ToCharset(
                (ch & 0xf8) == 0xf0)
         *destptr++ = '?';
       else if (!(ch & 0x80))
-       *destptr++ = ch;
+       *destptr++ = (char)ch;
     }
 
     *destptr = '\0';
@@ -287,11 +282,15 @@ cupsUTF8ToCharset(
 
   if (map_encoding != encoding)
   {
+    char       toset[1024];            /* Destination character set */
+
     _cupsCharmapFlush();
 
-    map_from_utf8 = iconv_open(_cupsEncodingName(encoding), "UTF-8");
-    map_to_utf8   = iconv_open("UTF-8", _cupsEncodingName(encoding));
+    snprintf(toset, sizeof(toset), "%s//IGNORE", _cupsEncodingName(encoding));
+
     map_encoding  = encoding;
+    map_from_utf8 = iconv_open(_cupsEncodingName(encoding), "UTF-8");
+    map_to_utf8   = iconv_open("UTF-8", toset);
   }
 
   if (map_from_utf8 != (iconv_t)-1)
@@ -299,7 +298,7 @@ cupsUTF8ToCharset(
     char *altsrc = (char *)src;                /* Silence bogus GCC type-punned */
 
     srclen       = strlen((char *)src);
-    outBytesLeft = maxout - 1;
+    outBytesLeft = (size_t)maxout - 1;
 
     iconv(map_from_utf8, &altsrc, &srclen, &destptr, &outBytesLeft);
     *destptr = '\0';
@@ -354,8 +353,7 @@ cupsUTF8ToUTF32(
   * Check for valid arguments and clear output...
   */
 
-  DEBUG_printf(("2cupsUTF8ToUTF32(dest=%p, src=\"%s\", maxout=%d)", dest,
-                src, maxout));
+  DEBUG_printf(("2cupsUTF8ToUTF32(dest=%p, src=\"%s\", maxout=%d)", (void *)dest, src, maxout));
 
   if (dest)
     *dest = 0;
@@ -404,7 +402,7 @@ cupsUTF8ToUTF32(
        return (-1);
       }
 
-      ch32 = ((ch & 0x1f) << 6) | (next & 0x3f);
+      ch32 = (cups_utf32_t)((ch & 0x1f) << 6) | (cups_utf32_t)(next & 0x3f);
 
      /*
       * Check for non-shortest form (invalid UTF-8)...
@@ -436,7 +434,7 @@ cupsUTF8ToUTF32(
        return (-1);
       }
 
-      ch32 = ((ch & 0x0f) << 6) | (next & 0x3f);
+      ch32 = (cups_utf32_t)((ch & 0x0f) << 6) | (cups_utf32_t)(next & 0x3f);
 
       next = *src++;
       if ((next & 0xc0) != 0x80)
@@ -446,7 +444,7 @@ cupsUTF8ToUTF32(
        return (-1);
       }
 
-      ch32 = (ch32 << 6) | (next & 0x3f);
+      ch32 = (ch32 << 6) | (cups_utf32_t)(next & 0x3f);
 
      /*
       * Check for non-shortest form (invalid UTF-8)...
@@ -478,7 +476,7 @@ cupsUTF8ToUTF32(
        return (-1);
       }
 
-      ch32 = ((ch & 0x07) << 6) | (next & 0x3f);
+      ch32 = (cups_utf32_t)((ch & 0x07) << 6) | (cups_utf32_t)(next & 0x3f);
 
       next = *src++;
       if ((next & 0xc0) != 0x80)
@@ -488,7 +486,7 @@ cupsUTF8ToUTF32(
        return (-1);
       }
 
-      ch32 = (ch32 << 6) | (next & 0x3f);
+      ch32 = (ch32 << 6) | (cups_utf32_t)(next & 0x3f);
 
       next = *src++;
       if ((next & 0xc0) != 0x80)
@@ -498,7 +496,7 @@ cupsUTF8ToUTF32(
        return (-1);
       }
 
-      ch32 = (ch32 << 6) | (next & 0x3f);
+      ch32 = (ch32 << 6) | (cups_utf32_t)(next & 0x3f);
 
      /*
       * Check for non-shortest form (invalid UTF-8)...
@@ -575,8 +573,7 @@ cupsUTF32ToUTF8(
   * Check for valid arguments and clear output...
   */
 
-  DEBUG_printf(("2cupsUTF32ToUTF8(dest=%p, src=%p, maxout=%d)", dest, src,
-                maxout));
+  DEBUG_printf(("2cupsUTF32ToUTF8(dest=%p, src=%p, maxout=%d)", (void *)dest, (void *)src, maxout));
 
   if (dest)
     *dest = '\0';