Skip to content

Commit f6c2721

Browse files
committed
fix: render a non-ascii chars in proc list
1 parent 6164470 commit f6c2721

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/btop_tools.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,17 @@ namespace Tools {
222222
}
223223
vector<wchar_t> w_str(w_len);
224224
std::mbstowcs(&w_str[0], str_data, w_len);
225-
for (size_t i = 0; i < w_str.size(); i++) {
225+
for (size_t i = 0; i < w_str.size() - 1; i++) {
226226
if (widechar_wcwidth(w_str[i]) > 1)
227227
continue;
228228
if (w_str[i] < 0x20)
229229
w_str[i] = replacement;
230230
}
231-
str.resize(w_str.size());
232-
std::wcstombs(&str[0], &w_str[0], w_str.size());
231+
size_t bytes = std::wcstombs(nullptr, w_str.data(), 0);
232+
if (bytes == static_cast<size_t>(-1))
233+
return str;
234+
str.resize(bytes);
235+
std::wcstombs(&str[0], &w_str[0], bytes);
233236

234237
return str;
235238
}

0 commit comments

Comments
 (0)