From 7aace8ea6da9c58782e74b3bfc5f8928b06d6853 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Sun, 21 Apr 2024 02:20:32 +0200 Subject: [PATCH] Avoid redundant arguments Remove redundant arguments where the method already has access to the relevant variable as an object attribute. --- common/rfb/SSecurityTLS.cxx | 4 +-- common/rfb/SSecurityTLS.h | 2 +- common/rfb/ZRLEDecoder.cxx | 63 +++++++++++++++++------------------ common/rfb/ZRLEDecoder.h | 1 - unix/x0vncserver/XDesktop.cxx | 20 +++++------ unix/x0vncserver/XDesktop.h | 8 ++--- 6 files changed, 48 insertions(+), 50 deletions(-) diff --git a/common/rfb/SSecurityTLS.cxx b/common/rfb/SSecurityTLS.cxx index 0b8f0ff2..c55f1be8 100644 --- a/common/rfb/SSecurityTLS.cxx +++ b/common/rfb/SSecurityTLS.cxx @@ -151,7 +151,7 @@ bool SSecurityTLS::processMsg() throw AuthFailureException("gnutls_set_default_priority failed"); try { - setParams(session); + setParams(); } catch(...) { os->writeU8(0); @@ -190,7 +190,7 @@ bool SSecurityTLS::processMsg() return true; } -void SSecurityTLS::setParams(gnutls_session_t session) +void SSecurityTLS::setParams() { static const char kx_anon_priority[] = ":+ANON-ECDH:+ANON-DH"; diff --git a/common/rfb/SSecurityTLS.h b/common/rfb/SSecurityTLS.h index 0b9ea9f3..c29ee474 100644 --- a/common/rfb/SSecurityTLS.h +++ b/common/rfb/SSecurityTLS.h @@ -54,7 +54,7 @@ namespace rfb { protected: void shutdown(); - void setParams(gnutls_session_t session); + void setParams(); private: gnutls_session_t session; diff --git a/common/rfb/ZRLEDecoder.cxx b/common/rfb/ZRLEDecoder.cxx index de919dc5..474fd6ca 100644 --- a/common/rfb/ZRLEDecoder.cxx +++ b/common/rfb/ZRLEDecoder.cxx @@ -106,20 +106,19 @@ void ZRLEDecoder::decodeRect(const Rect& r, const uint8_t* buffer, rdr::MemInStream is(buffer, buflen); const rfb::PixelFormat& pf = server.pf(); switch (pf.bpp) { - case 8: zrleDecode(r, &is, &zis, pf, pb); break; - case 16: zrleDecode(r, &is, &zis, pf, pb); break; - case 32: zrleDecode(r, &is, &zis, pf, pb); break; + case 8: zrleDecode(r, &is, pf, pb); break; + case 16: zrleDecode(r, &is, pf, pb); break; + case 32: zrleDecode(r, &is, pf, pb); break; } } template void ZRLEDecoder::zrleDecode(const Rect& r, rdr::InStream* is, - rdr::ZlibInStream* zis, const PixelFormat& pf, ModifiablePixelBuffer* pb) { int length = is->readU32(); - zis->setUnderlying(is, length); + zis.setUnderlying(is, length); Rect t; T buf[64 * 64]; @@ -141,24 +140,24 @@ void ZRLEDecoder::zrleDecode(const Rect& r, rdr::InStream* is, t.br.x = __rfbmin(r.br.x, t.tl.x + 64); - zlibHasData(zis, 1); - int mode = zis->readU8(); + zlibHasData(&zis, 1); + int mode = zis.readU8(); bool rle = mode & 128; int palSize = mode & 127; T palette[128]; if (isLowCPixel || isHighCPixel) - zlibHasData(zis, 3 * palSize); + zlibHasData(&zis, 3 * palSize); else - zlibHasData(zis, sizeof(T) * palSize); + zlibHasData(&zis, sizeof(T) * palSize); for (int i = 0; i < palSize; i++) { if (isLowCPixel) - palette[i] = readOpaque24A(zis); + palette[i] = readOpaque24A(&zis); else if (isHighCPixel) - palette[i] = readOpaque24B(zis); + palette[i] = readOpaque24B(&zis); else - palette[i] = readPixel(zis); + palette[i] = readPixel(&zis); } if (palSize == 1) { @@ -173,19 +172,19 @@ void ZRLEDecoder::zrleDecode(const Rect& r, rdr::InStream* is, // raw if (isLowCPixel || isHighCPixel) - zlibHasData(zis, 3 * t.area()); + zlibHasData(&zis, 3 * t.area()); else - zlibHasData(zis, sizeof(T) * t.area()); + zlibHasData(&zis, sizeof(T) * t.area()); if (isLowCPixel || isHighCPixel) { for (T* ptr = buf; ptr < buf+t.area(); ptr++) { if (isLowCPixel) - *ptr = readOpaque24A(zis); + *ptr = readOpaque24A(&zis); else - *ptr = readOpaque24B(zis); + *ptr = readOpaque24B(&zis); } } else { - zis->readBytes((uint8_t*)buf, t.area() * sizeof(T)); + zis.readBytes((uint8_t*)buf, t.area() * sizeof(T)); } } else { @@ -203,8 +202,8 @@ void ZRLEDecoder::zrleDecode(const Rect& r, rdr::InStream* is, while (ptr < eol) { if (nbits == 0) { - zlibHasData(zis, 1); - byte = zis->readU8(); + zlibHasData(&zis, 1); + byte = zis.readU8(); nbits = 8; } nbits -= bppp; @@ -225,20 +224,20 @@ void ZRLEDecoder::zrleDecode(const Rect& r, rdr::InStream* is, while (ptr < end) { T pix; if (isLowCPixel || isHighCPixel) - zlibHasData(zis, 3); + zlibHasData(&zis, 3); else - zlibHasData(zis, sizeof(T)); + zlibHasData(&zis, sizeof(T)); if (isLowCPixel) - pix = readOpaque24A(zis); + pix = readOpaque24A(&zis); else if (isHighCPixel) - pix = readOpaque24B(zis); + pix = readOpaque24B(&zis); else - pix = readPixel(zis); + pix = readPixel(&zis); int len = 1; int b; do { - zlibHasData(zis, 1); - b = zis->readU8(); + zlibHasData(&zis, 1); + b = zis.readU8(); len += b; } while (b == 255); @@ -256,14 +255,14 @@ void ZRLEDecoder::zrleDecode(const Rect& r, rdr::InStream* is, T* ptr = buf; T* end = ptr + t.area(); while (ptr < end) { - zlibHasData(zis, 1); - int index = zis->readU8(); + zlibHasData(&zis, 1); + int index = zis.readU8(); int len = 1; if (index & 128) { int b; do { - zlibHasData(zis, 1); - b = zis->readU8(); + zlibHasData(&zis, 1); + b = zis.readU8(); len += b; } while (b == 255); @@ -285,6 +284,6 @@ void ZRLEDecoder::zrleDecode(const Rect& r, rdr::InStream* is, } } - zis->flushUnderlying(); - zis->setUnderlying(nullptr, 0); + zis.flushUnderlying(); + zis.setUnderlying(nullptr, 0); } diff --git a/common/rfb/ZRLEDecoder.h b/common/rfb/ZRLEDecoder.h index 9ed2c2c8..facf0adc 100644 --- a/common/rfb/ZRLEDecoder.h +++ b/common/rfb/ZRLEDecoder.h @@ -40,7 +40,6 @@ namespace rfb { private: template void zrleDecode(const Rect& r, rdr::InStream* is, - rdr::ZlibInStream* zis, const PixelFormat& pf, ModifiablePixelBuffer* pb); private: diff --git a/unix/x0vncserver/XDesktop.cxx b/unix/x0vncserver/XDesktop.cxx index ba1d5b2b..4286c541 100644 --- a/unix/x0vncserver/XDesktop.cxx +++ b/unix/x0vncserver/XDesktop.cxx @@ -285,7 +285,7 @@ void XDesktop::stop() { #ifdef HAVE_XTEST // Delete added keycodes - deleteAddedKeysyms(dpy); + deleteAddedKeysyms(); #endif #ifdef HAVE_XDAMAGE @@ -368,7 +368,7 @@ void XDesktop::pointerEvent(const Point& pos, int buttonMask) { } #ifdef HAVE_XTEST -KeyCode XDesktop::XkbKeysymToKeycode(Display* dpy, KeySym keysym) { +KeyCode XDesktop::XkbKeysymToKeycode(KeySym keysym) { XkbDescPtr xkb; XkbStateRec state; unsigned int mods; @@ -401,12 +401,12 @@ KeyCode XDesktop::XkbKeysymToKeycode(Display* dpy, KeySym keysym) { // Shift+Tab is usually ISO_Left_Tab, but RFB hides this fact. Do // another attempt if we failed the initial lookup if ((keycode == 0) && (keysym == XK_Tab) && (mods & ShiftMask)) - return XkbKeysymToKeycode(dpy, XK_ISO_Left_Tab); + return XkbKeysymToKeycode(XK_ISO_Left_Tab); return keycode; } -KeyCode XDesktop::addKeysym(Display* dpy, KeySym keysym) +KeyCode XDesktop::addKeysym(KeySym keysym) { int types[1]; unsigned int key; @@ -460,7 +460,7 @@ KeyCode XDesktop::addKeysym(Display* dpy, KeySym keysym) return 0; } -void XDesktop::deleteAddedKeysyms(Display* dpy) { +void XDesktop::deleteAddedKeysyms() { XkbDescPtr xkb; xkb = XkbGetMap(dpy, XkbAllComponentsMask, XkbUseCoreKbd); @@ -476,7 +476,7 @@ void XDesktop::deleteAddedKeysyms(Display* dpy) { for (it = addedKeysyms.begin(); it != addedKeysyms.end(); it++) { if (XkbKeyNumGroups(xkb, it->second) != 0) { // Check if we are removing keysym we added ourself - if (XkbKeysymToKeycode(dpy, it->first) != it->second) + if (XkbKeysymToKeycode(it->first) != it->second) continue; XkbChangeTypesOfKey(xkb, it->second, 0, XkbGroup1Mask, nullptr, &changes); @@ -501,19 +501,19 @@ void XDesktop::deleteAddedKeysyms(Display* dpy) { addedKeysyms.clear(); } -KeyCode XDesktop::keysymToKeycode(Display* dpy, KeySym keysym) { +KeyCode XDesktop::keysymToKeycode(KeySym keysym) { int keycode = 0; // XKeysymToKeycode() doesn't respect state, so we have to use // something slightly more complex - keycode = XkbKeysymToKeycode(dpy, keysym); + keycode = XkbKeysymToKeycode(keysym); if (keycode != 0) return keycode; // TODO: try to further guess keycode with all possible mods as Xvnc does - keycode = addKeysym(dpy, keysym); + keycode = addKeysym(keysym); if (keycode == 0) vlog.error("Failure adding new keysym 0x%lx", keysym); @@ -538,7 +538,7 @@ void XDesktop::keyEvent(uint32_t keysym, uint32_t xtcode, bool down) { if (pressedKeys.find(keysym) != pressedKeys.end()) keycode = pressedKeys[keysym]; else { - keycode = keysymToKeycode(dpy, keysym); + keycode = keysymToKeycode(keysym); } } diff --git a/unix/x0vncserver/XDesktop.h b/unix/x0vncserver/XDesktop.h index c707fc6b..125ddeb0 100644 --- a/unix/x0vncserver/XDesktop.h +++ b/unix/x0vncserver/XDesktop.h @@ -101,10 +101,10 @@ protected: protected: #ifdef HAVE_XTEST - KeyCode XkbKeysymToKeycode(Display* dpy, KeySym keysym); - KeyCode addKeysym(Display* dpy, KeySym keysym); - void deleteAddedKeysyms(Display* dpy); - KeyCode keysymToKeycode(Display* dpy, KeySym keysym); + KeyCode XkbKeysymToKeycode(KeySym keysym); + KeyCode addKeysym(KeySym keysym); + void deleteAddedKeysyms(); + KeyCode keysymToKeycode(KeySym keysym); #endif #ifdef HAVE_XFIXES bool setCursor(); -- 2.39.5