diff options
author | ache <ache@FreeBSD.org> | 2008-01-23 02:17:27 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2008-01-23 02:17:27 +0000 |
commit | 28095b28d0319f9b3ee4e99003a257035cb5c11e (patch) | |
tree | f22641d5995df35d7c0dd3a78c3182b726840d04 /lib/libc/locale | |
parent | 76c6a978cca445992be3228df0af5c665fbc1083 (diff) | |
download | FreeBSD-src-28095b28d0319f9b3ee4e99003a257035cb5c11e.zip FreeBSD-src-28095b28d0319f9b3ee4e99003a257035cb5c11e.tar.gz |
Better fix for longstanding segfault. Don't touch current locale at all
on unknown encoding. Previous fix resets it to POSIX.
Diffstat (limited to 'lib/libc/locale')
-rw-r--r-- | lib/libc/locale/setrunelocale.c | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/lib/libc/locale/setrunelocale.c b/lib/libc/locale/setrunelocale.c index 4e36eb7..b4820bb 100644 --- a/lib/libc/locale/setrunelocale.c +++ b/lib/libc/locale/setrunelocale.c @@ -51,6 +51,15 @@ extern _RuneLocale *_Read_RuneMagi(FILE *); static int __setrunelocale(const char *); +static void convinit(void) +{ + __mbrtowc = NULL; + __mbsinit = NULL; + __mbsnrtowcs = __mbsnrtowcs_std; + __wcrtomb = NULL; + __wcsnrtombs = __wcsnrtombs_std; +} + static int __setrunelocale(const char *encoding) { @@ -117,35 +126,38 @@ __setrunelocale(const char *encoding) } (void)fclose(fp); - __mbrtowc = NULL; - __mbsinit = NULL; - __mbsnrtowcs = __mbsnrtowcs_std; - __wcrtomb = NULL; - __wcsnrtombs = __wcsnrtombs_std; rl->__sputrune = NULL; rl->__sgetrune = NULL; - if (strcmp(rl->__encoding, "NONE") == 0) + if (strcmp(rl->__encoding, "NONE") == 0) { + convinit(); ret = _none_init(rl); - else if (strcmp(rl->__encoding, "ASCII") == 0) + } else if (strcmp(rl->__encoding, "ASCII") == 0) { + convinit(); ret = _ascii_init(rl); - else if (strcmp(rl->__encoding, "UTF-8") == 0) + } else if (strcmp(rl->__encoding, "UTF-8") == 0) { + convinit(); ret = _UTF8_init(rl); - else if (strcmp(rl->__encoding, "EUC") == 0) + } else if (strcmp(rl->__encoding, "EUC") == 0) { + convinit(); ret = _EUC_init(rl); - else if (strcmp(rl->__encoding, "GB18030") == 0) + } else if (strcmp(rl->__encoding, "GB18030") == 0) { + convinit(); ret = _GB18030_init(rl); - else if (strcmp(rl->__encoding, "GB2312") == 0) + } else if (strcmp(rl->__encoding, "GB2312") == 0) { + convinit(); ret = _GB2312_init(rl); - else if (strcmp(rl->__encoding, "GBK") == 0) + } else if (strcmp(rl->__encoding, "GBK") == 0) { + convinit(); ret = _GBK_init(rl); - else if (strcmp(rl->__encoding, "BIG5") == 0) + } else if (strcmp(rl->__encoding, "BIG5") == 0) { + convinit(); ret = _BIG5_init(rl); - else if (strcmp(rl->__encoding, "MSKanji") == 0) + } else if (strcmp(rl->__encoding, "MSKanji") == 0) { + convinit(); ret = _MSKanji_init(rl); - else { - (void) _none_init(&_DefaultRuneLocale); + } else ret = EFTYPE; - } + if (ret == 0) { if (CachedRuneLocale != NULL) { /* See euc.c */ |