all repos — fluxbox @ 8b44c7a184e33aaacc6834b19efa88be058a4a4a

custom fork of the fluxbox windowmanager

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
commit

8b44c7a184e33aaacc6834b19efa88be058a4a4a

parent

8e5a10ea6c7384a92f572863e12d3c578c06c023

1 files changed, 3 insertions(+), 9 deletions(-)

jump to
M src/Ewmh.ccsrc/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) {