File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11//
22// Transcoding support for CUPS.
33//
4- // Copyright © 2022 by OpenPrinting.
4+ // Copyright © 2020-2025 by OpenPrinting.
55// Copyright © 2007-2014 by Apple Inc.
66// Copyright © 1997-2007 by Easy Software Products.
77//
@@ -156,7 +156,6 @@ cupsCharsetToUTF8(
156156 int ch ; // Character from string
157157 char * destend ; // End of UTF-8 buffer
158158
159-
160159 destend = dest + maxout - 2 ;
161160
162161 while (* src && destptr < destend )
@@ -169,7 +168,9 @@ cupsCharsetToUTF8(
169168 * destptr ++ = (char )(0x80 | (ch & 0x3f ));
170169 }
171170 else
171+ {
172172 * destptr ++ = (char )ch ;
173+ }
173174 }
174175
175176 * destptr = '\0' ;
@@ -311,8 +312,9 @@ cupsUTF8ToCharset(
311312 {
312313 ch = * src ++ ;
313314
314- if ((ch & 0xe0 ) == 0xc0 )
315+ if ((ch & 0xe0 ) == 0xc0 && ( * src & 0xc0 ) == 0x80 )
315316 {
317+ // 2-byte UTF-8
316318 ch = ((ch & 0x1f ) << 6 ) | (* src ++ & 0x3f );
317319
318320 if (ch < maxch )
@@ -322,10 +324,12 @@ cupsUTF8ToCharset(
322324 }
323325 else if ((ch & 0xf0 ) == 0xe0 || (ch & 0xf8 ) == 0xf0 )
324326 {
327+ // 3-byte or 4-byte UTF-8
325328 * destptr ++ = '?' ;
326329 }
327330 else if (!(ch & 0x80 ))
328331 {
332+ // ASCII
329333 * destptr ++ = (char )ch ;
330334 }
331335 }
You can’t perform that action at this time.
0 commit comments