diff --git a/libs/main/core/pistring.cpp b/libs/main/core/pistring.cpp index 9b00c3f4..26830b38 100644 --- a/libs/main/core/pistring.cpp +++ b/libs/main/core/pistring.cpp @@ -234,19 +234,19 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) { mbstate_t state; memset(&state, 0, sizeof(state)); const char ** pc; - const char * cc_; + char * c_ = nullptr; if (s > 0) { - char c_ [s+1]; + c_ = malloc(s+1); memcpy(c_, c, s); c_[s] = '\0'; - cc_ = &c_[0]; - pc = &cc_; + pc = &c_; } else { pc = &c; } size_t len = mbsrtowcs(NULL, pc, 0, &state); wchar_t wstr[len+1]; mbsrtowcs(&wstr[0], pc, len+1, &state); + if (s > 0) free(c_); enlarge(len); for (size_t i=0; i