Don't assume ICONV_NULL = 0
We define the value ICONV_NULL = -1, but when we attempt to set the s_iconv_convs array to all NULL values, we zero the array instead of setting its entries to -1. This patch properly initializes and wipes s_iconv_convs.
This commit is contained in:
parent
88a74ff1cd
commit
79a358346a
1 changed files with 9 additions and 5 deletions
|
@ -168,6 +168,10 @@ void init() {
|
|||
s_inited = true;
|
||||
setlocale(LC_CTYPE, "");
|
||||
|
||||
for (int i = 0; i < CONVSIZE; i++) {
|
||||
s_iconv_convs[i] = ICONV_NULL;
|
||||
}
|
||||
|
||||
#ifdef HAVE_ICONV
|
||||
#if defined(CODESET) && !defined(_WIN32)
|
||||
s_locale_codeset = nl_langinfo(CODESET);
|
||||
|
@ -186,8 +190,6 @@ void init() {
|
|||
s_iconv_convs[X2FB] = iconv_open("UTF-8", "ISO8859-1");
|
||||
s_iconv_convs[FB2LOCALE] = iconv_open(s_locale_codeset.c_str(), "UTF-8");
|
||||
s_iconv_convs[LOCALE2FB] = iconv_open("UTF-8", s_locale_codeset.c_str());
|
||||
#else
|
||||
memset(s_iconv_convs, 0, sizeof(s_iconv_convs));
|
||||
#endif // HAVE_ICONV
|
||||
|
||||
}
|
||||
|
@ -195,11 +197,13 @@ void init() {
|
|||
void shutdown() {
|
||||
#ifdef HAVE_ICONV
|
||||
int i;
|
||||
for (i = 0; i < CONVSIZE; ++i)
|
||||
if (s_iconv_convs[i] != ICONV_NULL)
|
||||
for (i = 0; i < CONVSIZE; ++i) {
|
||||
if (s_iconv_convs[i] != ICONV_NULL) {
|
||||
iconv_close(s_iconv_convs[i]);
|
||||
s_iconv_convs[i] = ICONV_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
memset(s_iconv_convs, 0, sizeof(s_iconv_convs));
|
||||
s_inited = false;
|
||||
#endif // HAVE_ICONV
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue