X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2FXAtom.cc;h=62a8f710b3c770e7ea4e3958a11f464fda5ad620;hb=e9f582ae978c5c1b6f2dea9bd9466f37fcb0564c;hp=545739ab0390f5cbb659180717ff2c7ebbe14ab9;hpb=f4c0547b7a90c9647a2c39c3d1a737142eab088e;p=chaz%2Fopenbox diff --git a/src/XAtom.cc b/src/XAtom.cc index 545739ab..62a8f710 100644 --- a/src/XAtom.cc +++ b/src/XAtom.cc @@ -357,12 +357,14 @@ bool XAtom::getValue(Window win, Atom atom, Atom type, Atom ret_type; int ret_size; unsigned long ret_bytes; + int result; const unsigned long maxread = nelements; // try get the first element - XGetWindowProperty(_display, win, atom, 0l, 1l, False, AnyPropertyType, - &ret_type, &ret_size, &nelements, &ret_bytes, &c_val); - if (ret_type == None || nelements < 1) - // the property does not exist on the window or is empty + result = XGetWindowProperty(_display, win, atom, 0l, 1l, False, + AnyPropertyType, &ret_type, &ret_size, + &nelements, &ret_bytes, &c_val); + if (result != Success || ret_type == None || nelements < 1) + // an error occured, the property does not exist on the window, or is empty return false; if (ret_type != type || ret_size != size) { // wrong data in property @@ -384,8 +386,10 @@ bool XAtom::getValue(Window win, Atom atom, Atom type, int remain = (ret_bytes - 1)/sizeof(long) + 1 + 1; if (remain > size/8 * (signed)maxread) // dont get more than the max remain = size/8 * (signed)maxread; - XGetWindowProperty(_display, win, atom, 0l, remain, False, type, &ret_type, - &ret_size, &nelements, &ret_bytes, &c_val); + result = XGetWindowProperty(_display, win, atom, 0l, remain, False, type, + &ret_type, &ret_size, &nelements, &ret_bytes, + &c_val); + assert(result == Success); assert(ret_bytes == 0); *value = new unsigned char[nelements * size/8 + 1]; memcpy(*value, c_val, nelements * size/8 + 1); @@ -430,7 +434,7 @@ bool XAtom::getValue(Window win, Atoms atom, Atoms type, */ bool XAtom::getValue(Window win, Atoms atom, StringType type, std::string &value) const { - int n = 1; + unsigned long n = 1; StringVect s; if (getValue(win, atom, type, n, s)) { value = s[0]; @@ -440,8 +444,8 @@ bool XAtom::getValue(Window win, Atoms atom, StringType type, } -bool XAtom::getValue(Window win, Atoms atom, StringType type, int &nelements, - StringVect &strings) const { +bool XAtom::getValue(Window win, Atoms atom, StringType type, + unsigned long &nelements, StringVect &strings) const { assert(atom >= 0 && atom < NUM_ATOMS); assert(type >= 0 && type < NUM_STRING_TYPE); assert(win != None); assert(_atoms[atom] != None); @@ -459,22 +463,22 @@ bool XAtom::getValue(Window win, Atoms atom, StringType type, int &nelements, if (!getValue(win, _atoms[atom], t, elements, &value, 8) || elements < 1) return false; - std::string s(reinterpret_cast(value)); + std::string s(reinterpret_cast(value), elements); delete [] value; std::string::const_iterator it = s.begin(), end = s.end(); - int num = 0; + unsigned long num = 0; while(num < nelements) { std::string::const_iterator tmp = it; // current string.begin() it = std::find(tmp, end, '\0'); // look for null between tmp and end strings.push_back(std::string(tmp, it)); // s[tmp:it) - if (it == end) - break; + if (it == end) break; ++it; + if (it == end) break; ++num; } - nelements = elements; + nelements = num; return true; }