annotate include/SDL_platform.h @ 4388:1524d3237820 SDL-1.2

Fixed bug #896 John Popplewell 2009-12-08 23:05:50 PST Originally reported by AKFoerster on the mailing list. Error decoding UTF8 Russian text to UTF-16LE on Windows, but specifically on platforms without iconv support (the default on Windows). Valid UTF8 characters are flagged as being overlong and then substituted by the UNKNOWN_UNICODE character. After studying the testiconv.c example program, reading the RFCs and putting some printf statements in SDL_iconv.c the problem is in a test for 'Maximum overlong sequences', specifically 4.2.1, which is carried out by the following code: } else if ( p[0] >= 0xC0 ) { if ( (p[0] & 0xE0) != 0xC0 ) { /* Skip illegal sequences return SDL_ICONV_EILSEQ; */ ch = UNKNOWN_UNICODE; } else { if ( (p[0] & 0xCE) == 0xC0 ) { <<<<<<<< here overlong = SDL_TRUE; } ch = (Uint32)(p[0] & 0x1F); left = 1; } } else { Here is the 2-byte encoding of a character in range 00000080 - 000007FF 110xxxxx 10xxxxxx The line in question is supposed to be checking for an overlong sequence which would be less than 11000001 10111111 which should be represented as a single byte. BUT, the mask value (0xCE) is wrong, it isn't checking the top-most bit: 11000001 value 11001110 mask (incorrect) ^ and should be (0xDE): 11000001 value 11011110 mask (correct) making the above code: } else if ( p[0] >= 0xC0 ) { if ( (p[0] & 0xE0) != 0xC0 ) { /* Skip illegal sequences return SDL_ICONV_EILSEQ; */ ch = UNKNOWN_UNICODE; } else { if ( (p[0] & 0xDE) == 0xC0 ) { <<<<<<<< here overlong = SDL_TRUE; } ch = (Uint32)(p[0] & 0x1F); left = 1; } } else { I can supply a test program and/or a patch if required, best regards, John Popplewell
author Sam Lantinga <slouken@libsdl.org>
date Fri, 11 Dec 2009 08:00:57 +0000
parents ecb22f65f0aa
children
rev   line source
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
4159
a1b03ba2fcd0 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 3888
diff changeset
3 Copyright (C) 1997-2009 Sam Lantinga
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22
4217
4c4113c2162c Fixed bug #706
Sam Lantinga <slouken@libsdl.org>
parents: 4164
diff changeset
23 /** @file SDL_platform.h
4c4113c2162c Fixed bug #706
Sam Lantinga <slouken@libsdl.org>
parents: 4164
diff changeset
24 * Try to get a standard set of platform defines
4c4113c2162c Fixed bug #706
Sam Lantinga <slouken@libsdl.org>
parents: 4164
diff changeset
25 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26
1406
39ca9a4b22f3 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
27 #ifndef _SDL_platform_h
39ca9a4b22f3 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
28 #define _SDL_platform_h
39ca9a4b22f3 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
29
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 #if defined(_AIX)
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 #undef __AIX__
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 #define __AIX__ 1
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 #endif
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 #if defined(__BEOS__)
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 #undef __BEOS__
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 #define __BEOS__ 1
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 #endif
4164
7a4c511c980a Date: Fri, 6 Mar 2009 12:41:17 -0800
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
38 #if defined(__HAIKU__)
7a4c511c980a Date: Fri, 6 Mar 2009 12:41:17 -0800
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
39 #undef __HAIKU__
7a4c511c980a Date: Fri, 6 Mar 2009 12:41:17 -0800
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
40 #define __HAIKU__ 1
7a4c511c980a Date: Fri, 6 Mar 2009 12:41:17 -0800
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
41 #endif
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 #if defined(bsdi) || defined(__bsdi) || defined(__bsdi__)
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 #undef __BSDI__
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 #define __BSDI__ 1
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 #endif
1461
11134dc42da8 Updated for Dreamcast KOS June 2005 snapshot:
Sam Lantinga <slouken@libsdl.org>
parents: 1422
diff changeset
46 #if defined(_arch_dreamcast)
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 #undef __DREAMCAST__
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 #define __DREAMCAST__ 1
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 #endif
4305
ecb22f65f0aa Adapted from 215_kfreebsd_gnu.diff
Sam Lantinga <slouken@libsdl.org>
parents: 4217
diff changeset
50 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 #undef __FREEBSD__
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 #define __FREEBSD__ 1
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 #endif
4164
7a4c511c980a Date: Fri, 6 Mar 2009 12:41:17 -0800
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
54 #if defined(__HAIKU__)
7a4c511c980a Date: Fri, 6 Mar 2009 12:41:17 -0800
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
55 #undef __HAIKU__
7a4c511c980a Date: Fri, 6 Mar 2009 12:41:17 -0800
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
56 #define __HAIKU__ 1
7a4c511c980a Date: Fri, 6 Mar 2009 12:41:17 -0800
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
57 #endif
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 #if defined(hpux) || defined(__hpux) || defined(__hpux__)
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 #undef __HPUX__
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 #define __HPUX__ 1
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 #endif
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 #if defined(sgi) || defined(__sgi) || defined(__sgi__) || defined(_SGI_SOURCE)
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 #undef __IRIX__
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 #define __IRIX__ 1
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 #endif
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 #if defined(linux) || defined(__linux) || defined(__linux__)
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 #undef __LINUX__
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 #define __LINUX__ 1
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 #endif
1631
510b009a864c Fixed MacOS X and Solaris detection
Sam Lantinga <slouken@libsdl.org>
parents: 1628
diff changeset
70 #if defined(__APPLE__)
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 #undef __MACOSX__
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 #define __MACOSX__ 1
1802
54f63955dc1f Prevent both __MACOS__ and __MACOSX__ from being defined in Codewarrior
Sam Lantinga <slouken@libsdl.org>
parents: 1631
diff changeset
73 #elif defined(macintosh)
54f63955dc1f Prevent both __MACOS__ and __MACOSX__ from being defined in Codewarrior
Sam Lantinga <slouken@libsdl.org>
parents: 1631
diff changeset
74 #undef __MACOS__
54f63955dc1f Prevent both __MACOS__ and __MACOSX__ from being defined in Codewarrior
Sam Lantinga <slouken@libsdl.org>
parents: 1631
diff changeset
75 #define __MACOS__ 1
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 #endif
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 #if defined(__NetBSD__)
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 #undef __NETBSD__
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 #define __NETBSD__ 1
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 #endif
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 #if defined(__OpenBSD__)
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 #undef __OPENBSD__
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 #define __OPENBSD__ 1
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 #endif
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 #if defined(__OS2__)
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 #undef __OS2__
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 #define __OS2__ 1
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 #endif
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 #if defined(osf) || defined(__osf) || defined(__osf__) || defined(_OSF_SOURCE)
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 #undef __OSF__
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 #define __OSF__ 1
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 #endif
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 #if defined(__QNXNTO__)
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 #undef __QNXNTO__
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 #define __QNXNTO__ 1
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 #endif
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 #if defined(riscos) || defined(__riscos) || defined(__riscos__)
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 #undef __RISCOS__
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 #define __RISCOS__ 1
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 #endif
1631
510b009a864c Fixed MacOS X and Solaris detection
Sam Lantinga <slouken@libsdl.org>
parents: 1628
diff changeset
101 #if defined(__SVR4)
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 #undef __SOLARIS__
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 #define __SOLARIS__ 1
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 #endif
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 #if defined(WIN32) || defined(_WIN32)
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 #undef __WIN32__
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 #define __WIN32__ 1
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 #endif
1406
39ca9a4b22f3 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
109
39ca9a4b22f3 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
110 #endif /* _SDL_platform_h */