projects
/
musl
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
math: simplify hypot and hypotf using scalbn
[musl]
/
src
/
locale
/
iconv.c
diff --git
a/src/locale/iconv.c
b/src/locale/iconv.c
index
c48e45a
..
7b341fe
100644
(file)
--- a/
src/locale/iconv.c
+++ b/
src/locale/iconv.c
@@
-12,8
+12,8
@@
#define UTF_32LE 0303
#define UCS2BE 0304
#define UCS2LE 0305
#define UTF_32LE 0303
#define UCS2BE 0304
#define UCS2LE 0305
-#define
US_ASCII
0306
-#define
WCHAR_T
0307
+#define
WCHAR_T
0306
+#define
US_ASCII
0307
#define UTF_8 0310
#define EUC_JP 0320
#define SHIFT_JIS 0321
#define UTF_8 0310
#define EUC_JP 0320
#define SHIFT_JIS 0321
@@
-34,14
+34,14
@@
static const unsigned char charmaps[] =
"utf8\0\0\310"
static const unsigned char charmaps[] =
"utf8\0\0\310"
-"wchart\0\0\30
7
"
+"wchart\0\0\30
6
"
"ucs2\0ucs2be\0\0\304"
"ucs2le\0\0\305"
"utf16\0utf16be\0\0\302"
"utf16le\0\0\301"
"ucs4\0ucs4be\0utf32\0utf32be\0\0\300"
"ucs4le\0utf32le\0\0\303"
"ucs2\0ucs2be\0\0\304"
"ucs2le\0\0\305"
"utf16\0utf16be\0\0\302"
"utf16le\0\0\301"
"ucs4\0ucs4be\0utf32\0utf32be\0\0\300"
"ucs4le\0utf32le\0\0\303"
-"ascii\0usascii\0iso646\0iso646us\0\0\30
6
"
+"ascii\0usascii\0iso646\0iso646us\0\0\30
7
"
"eucjp\0\0\320"
"shiftjis\0sjis\0\0\321"
"gb18030\0\0\330"
"eucjp\0\0\320"
"shiftjis\0sjis\0\0\321"
"gb18030\0\0\330"
@@
-139,7
+139,7
@@
static void put_32(unsigned char *s, unsigned c, int e)
#define mbrtowc_utf8 mbrtowc
#define wctomb_utf8 wctomb
#define mbrtowc_utf8 mbrtowc
#define wctomb_utf8 wctomb
-size_t iconv(iconv_t cd0, char **
in, size_t *inb, char **out, size_t *
outb)
+size_t iconv(iconv_t cd0, char **
restrict in, size_t *restrict inb, char **restrict out, size_t *restrict
outb)
{
size_t x=0;
unsigned long cd = (unsigned long)cd0;
{
size_t x=0;
unsigned long cd = (unsigned long)cd0;
@@
-161,7
+161,7
@@
size_t iconv(iconv_t cd0, char **in, size_t *inb, char **out, size_t *outb)
c = *(unsigned char *)*in;
l = 1;
c = *(unsigned char *)*in;
l = 1;
- if (c >= 128) switch (type) {
+ if (c >= 128
|| type-UTF_32BE < 7U
) switch (type) {
case UTF_8:
l = mbrtowc_utf8(&wc, *in, *inb, &st);
if (!l) l++;
case UTF_8:
l = mbrtowc_utf8(&wc, *in, *inb, &st);
if (!l) l++;
@@
-196,9
+196,9
@@
size_t iconv(iconv_t cd0, char **in, size_t *inb, char **out, size_t *outb)
if (type-UCS2BE < 2U) goto ilseq;
l = 4;
if (*inb < 4) goto starved;
if (type-UCS2BE < 2U) goto ilseq;
l = 4;
if (*inb < 4) goto starved;
- d = get_16((void *)(*in + 2),
from
);
- if ((unsigned)(
c
-0xdc00) >= 0x400) goto ilseq;
- c = ((c-0xd
800)<<10) |
(d-0xdc00);
+ d = get_16((void *)(*in + 2),
type
);
+ if ((unsigned)(
d
-0xdc00) >= 0x400) goto ilseq;
+ c = ((c-0xd
7c0)<<10) +
(d-0xdc00);
}
break;
case SHIFT_JIS:
}
break;
case SHIFT_JIS:
@@
-327,14
+327,14
@@
size_t iconv(iconv_t cd0, char **in, size_t *inb, char **out, size_t *outb)
case UCS2LE:
case UTF_16BE:
case UTF_16LE:
case UCS2LE:
case UTF_16BE:
case UTF_16LE:
- if (c < 0x10000) {
+ if (c < 0x10000 || type-UCS2BE < 2U) {
+ if (c >= 0x10000) c = 0xFFFD;
if (*outb < 2) goto toobig;
put_16((void *)*out, c, totype);
*out += 2;
*outb -= 2;
break;
}
if (*outb < 2) goto toobig;
put_16((void *)*out, c, totype);
*out += 2;
*outb -= 2;
break;
}
- if (type-UCS2BE < 2U) goto ilseq;
if (*outb < 4) goto toobig;
c -= 0x10000;
put_16((void *)*out, (c>>10)|0xd800, totype);
if (*outb < 4) goto toobig;
c -= 0x10000;
put_16((void *)*out, (c>>10)|0xd800, totype);