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).
Mathias Gumz akira@fluxbox.org
1 files changed,
3 insertions(+),
9 deletions(-)
jump to
M
src/Ewmh.cc
→
src/Ewmh.cc
@@ -821,17 +821,15 @@ XTextProperty text;
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<char**>(names), number_of_desks, XUTF8StringStyle, &text); if (code != XNoMemory && code != XLocaleNotSupported) { XSetTextProperty(FbTk::App::instance()->display(), screen.rootWindow().window(),@@ -848,11 +846,7 @@ XFree(text.value);
} #endif - for (size_t i = 0; i < number_of_desks; i++) - delete[] names[i]; - delete[] names; - } void Ewmh::updateCurrentWorkspace(BScreen &screen) {