From 79a358346a650a40c0e0f0409b264bf3e3cb23a4 Mon Sep 17 00:00:00 2001 From: Casey Dahlin Date: Thu, 9 Apr 2015 15:01:35 -0400 Subject: 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. --- src/FbTk/FbString.cc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/FbTk/FbString.cc b/src/FbTk/FbString.cc index 2bc7516..9c7fca7 100644 --- a/src/FbTk/FbString.cc +++ b/src/FbTk/FbString.cc @@ -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 } -- cgit v0.11.2