aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Gumz <akira@fluxbox.org>2015-01-29 10:38:48 (GMT)
committerMathias Gumz <akira@fluxbox.org>2015-01-29 10:38:48 (GMT)
commit8b44c7a184e33aaacc6834b19efa88be058a4a4a (patch)
tree7ece32ab9b73b4256075686b4c803b2a3a634b92
parent8e5a10ea6c7384a92f572863e12d3c578c06c023 (diff)
downloadfluxbox-8b44c7a184e33aaacc6834b19efa88be058a4a4a.zip
fluxbox-8b44c7a184e33aaacc6834b19efa88be058a4a4a.tar.bz2
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).
-rw-r--r--src/Ewmh.cc12
1 files 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) {
821 const BScreen::WorkspaceNames &workspacenames = screen.getWorkspaceNames(); 821 const BScreen::WorkspaceNames &workspacenames = screen.getWorkspaceNames();
822 const size_t number_of_desks = workspacenames.size(); 822 const size_t number_of_desks = workspacenames.size();
823 823
824 char** names = new char*[number_of_desks]; 824 const char** names = new const char*[number_of_desks];
825 825
826 for (size_t i = 0; i < number_of_desks; i++) { 826 for (size_t i = 0; i < number_of_desks; i++) {
827 names[i] = new char[workspacenames[i].size() + 1]; // +1 for \0 827 names[i] = workspacenames[i].c_str();
828 memset(names[i], 0, workspacenames[i].size());
829 strcpy(names[i], workspacenames[i].c_str());
830 } 828 }
831 829
832#ifdef X_HAVE_UTF8_STRING 830#ifdef X_HAVE_UTF8_STRING
833 int code = Xutf8TextListToTextProperty(FbTk::App::instance()->display(), 831 int code = Xutf8TextListToTextProperty(FbTk::App::instance()->display(),
834 names, number_of_desks, XUTF8StringStyle, &text); 832 const_cast<char**>(names), number_of_desks, XUTF8StringStyle, &text);
835 if (code != XNoMemory && code != XLocaleNotSupported) { 833 if (code != XNoMemory && code != XLocaleNotSupported) {
836 XSetTextProperty(FbTk::App::instance()->display(), 834 XSetTextProperty(FbTk::App::instance()->display(),
837 screen.rootWindow().window(), 835 screen.rootWindow().window(),
@@ -848,11 +846,7 @@ void Ewmh::updateWorkspaceNames(BScreen &screen) {
848 } 846 }
849#endif 847#endif
850 848
851 for (size_t i = 0; i < number_of_desks; i++)
852 delete[] names[i];
853
854 delete[] names; 849 delete[] names;
855
856} 850}
857 851
858void Ewmh::updateCurrentWorkspace(BScreen &screen) { 852void Ewmh::updateCurrentWorkspace(BScreen &screen) {