]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/transcode.c
Update svn:keyword properties.
[thirdparty/cups.git] / cups / transcode.c
index 0e33744ad254814eedf2fd0af371dd69e007043e..380807f950ccc1302ef82494c9628b556e976cc7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: transcode.c 9306 2010-09-16 21:43:57Z mike $"
+ * "$Id$"
  *
  *   Transcoding support for CUPS.
  *
@@ -171,16 +171,17 @@ cupsCharsetToUTF8(
 
   if (map_to_utf8 != (iconv_t)-1)
   {
+    char *altdestptr = (char *)dest;   /* Silence bogus GCC type-punned */
+
     srclen       = strlen(src);
     outBytesLeft = maxout - 1;
 
-    iconv(map_to_utf8, (char **)&src, &srclen, (char **)&destptr,
-         &outBytesLeft);
-    *destptr = '\0';
+    iconv(map_to_utf8, (char **)&src, &srclen, &altdestptr, &outBytesLeft);
+    *altdestptr = '\0';
 
     _cupsMutexUnlock(&map_mutex);
 
-    return ((int)(destptr - dest));
+    return ((int)(altdestptr - (char *)dest));
   }
 
   _cupsMutexUnlock(&map_mutex);
@@ -230,7 +231,7 @@ cupsUTF8ToCharset(
   * Handle identity conversions...
   */
 
-  if (encoding == CUPS_UTF8 || encoding <= CUPS_US_ASCII ||
+  if (encoding == CUPS_UTF8 ||
       encoding >= CUPS_ENCODING_VBCS_END)
   {
     strlcpy(dest, (char *)src, maxout);
@@ -243,12 +244,13 @@ cupsUTF8ToCharset(
 
   destptr = dest;
 
-  if (encoding == CUPS_ISO8859_1)
+  if (encoding == CUPS_ISO8859_1 || encoding <= CUPS_US_ASCII)
   {
-    int                ch;                     /* Character from string */
+    int                ch,                     /* Character from string */
+               maxch;                  /* Maximum character for charset */
     char       *destend;               /* End of ISO-8859-1 buffer */
 
-
+    maxch   = encoding == CUPS_ISO8859_1 ? 256 : 128;
     destend = dest + maxout - 1;
 
     while (*src && destptr < destend)
@@ -259,7 +261,7 @@ cupsUTF8ToCharset(
       {
        ch = ((ch & 0x1f) << 6) | (*src++ & 0x3f);
 
-       if (ch < 256)
+       if (ch < maxch)
           *destptr++ = ch;
        else
           *destptr++ = '?';
@@ -294,10 +296,12 @@ cupsUTF8ToCharset(
 
   if (map_from_utf8 != (iconv_t)-1)
   {
+    char *altsrc = (char *)src;                /* Silence bogus GCC type-punned */
+
     srclen       = strlen((char *)src);
     outBytesLeft = maxout - 1;
 
-    iconv(map_from_utf8, (char **)&src, &srclen, &destptr, &outBytesLeft);
+    iconv(map_from_utf8, &altsrc, &srclen, &destptr, &outBytesLeft);
     *destptr = '\0';
 
     _cupsMutexUnlock(&map_mutex);
@@ -712,5 +716,5 @@ cupsUTF32ToUTF8(
 
 
 /*
- * End of "$Id: transcode.c 9306 2010-09-16 21:43:57Z mike $"
+ * End of "$Id$"
  */