diff --git a/CRT.c b/CRT.c index 9c8b841a2..e9a1a60ed 100644 --- a/CRT.c +++ b/CRT.c @@ -12,6 +12,7 @@ in the source distribution for its full text. #include #include #include +#include #include #include #include @@ -94,21 +95,25 @@ const char* const* CRT_treeStr = CRT_treeStrAscii; static const Settings* CRT_settings; -const char* CRT_degreeSign; +#ifdef HAVE_LIBNCURSESW +char CRT_degreeSign[MB_LEN_MAX] = "\xc2\xb0"; +#else +char CRT_degreeSign[] = ""; +#endif -static const char* initDegreeSign(void) { +static void initDegreeSign(void) { #ifdef HAVE_LIBNCURSESW if (CRT_utf8) - return "\xc2\xb0"; + return; - static char buffer[4]; // this might fail if the current locale does not support wide characters - int r = snprintf(buffer, sizeof(buffer), "%lc", 176); - if (r > 0) - return buffer; + int r = snprintf(CRT_degreeSign, sizeof(CRT_degreeSign), "%lc", 176); + if (r <= 0) + CRT_degreeSign[0] = '\0'; #endif - return ""; + // No-op + return; } const int* CRT_colors; @@ -1145,7 +1150,7 @@ IGNORE_WCASTQUAL_END CRT_setMouse(settings->enableMouse); - CRT_degreeSign = initDegreeSign(); + initDegreeSign(); } void CRT_done(void) { diff --git a/CRT.h b/CRT.h index 1b2b5742d..204c9d179 100644 --- a/CRT.h +++ b/CRT.h @@ -176,7 +176,7 @@ void CRT_handleSIGSEGV(int signal) ATTR_NORETURN; #define KEY_FOCUS_IN (KEY_MAX + 'I') #define KEY_FOCUS_OUT (KEY_MAX + 'O') -extern const char* CRT_degreeSign; +extern char CRT_degreeSign[]; #ifdef HAVE_LIBNCURSESW