From 5ebf11115509387cdf7cd7c30869cbf1c3bcf2dd Mon Sep 17 00:00:00 2001 From: "Andrey A. Chernov" Date: Wed, 23 Jan 2008 02:17:27 +0000 Subject: [PATCH] Better fix for longstanding segfault. Don't touch current locale at all on unknown encoding. Previous fix resets it to POSIX. --- lib/libc/locale/setrunelocale.c | 46 +++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/lib/libc/locale/setrunelocale.c b/lib/libc/locale/setrunelocale.c index 4e36eb7bcf7b..b4820bbedf5c 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 */