From 8b44c7a184e33aaacc6834b19efa88be058a4a4a Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Thu, 29 Jan 2015 11:38:48 +0100 Subject: Simpler code to set _NET_DESKTOP_NAMES gcc-4.2.1 on OpenBSD-5.6 hinted that strcpy() is not the safest function on earth. While seeing the code I wondered why it we first create copies of the names at all (let alone using memset() and then strcpy() after it). --- src/Ewmh.cc | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Ewmh.cc b/src/Ewmh.cc index b6793e0..0da4190 100644 --- a/src/Ewmh.cc +++ b/src/Ewmh.cc @@ -821,17 +821,15 @@ void Ewmh::updateWorkspaceNames(BScreen &screen) { const BScreen::WorkspaceNames &workspacenames = screen.getWorkspaceNames(); const size_t number_of_desks = workspacenames.size(); - char** names = new char*[number_of_desks]; + const char** names = new const char*[number_of_desks]; for (size_t i = 0; i < number_of_desks; i++) { - names[i] = new char[workspacenames[i].size() + 1]; // +1 for \0 - memset(names[i], 0, workspacenames[i].size()); - strcpy(names[i], workspacenames[i].c_str()); + names[i] = workspacenames[i].c_str(); } #ifdef X_HAVE_UTF8_STRING int code = Xutf8TextListToTextProperty(FbTk::App::instance()->display(), - names, number_of_desks, XUTF8StringStyle, &text); + const_cast(names), number_of_desks, XUTF8StringStyle, &text); if (code != XNoMemory && code != XLocaleNotSupported) { XSetTextProperty(FbTk::App::instance()->display(), screen.rootWindow().window(), @@ -848,11 +846,7 @@ void Ewmh::updateWorkspaceNames(BScreen &screen) { } #endif - for (size_t i = 0; i < number_of_desks; i++) - delete[] names[i]; - delete[] names; - } void Ewmh::updateCurrentWorkspace(BScreen &screen) { -- cgit v0.11.2