Skip to content

Commit

Permalink
Avoid shadowing variables
Browse files Browse the repository at this point in the history
It's a source of confusion and possibly bugs to reuse the same variable
name for multiple things.
  • Loading branch information
CendioOssman committed Jun 24, 2024
1 parent 4a71ac5 commit 12b3f40
Show file tree
Hide file tree
Showing 68 changed files with 285 additions and 260 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
include(CheckIncludeFiles)
include(CheckFunctionExists)
include(CheckLibraryExists)
include(CheckVariableExists)
include(CheckTypeSize)
include(CheckCSourceCompiles)
include(CheckCXXSourceCompiles)
Expand Down Expand Up @@ -185,6 +186,13 @@ if(ENABLE_H264)
add_definitions("-DHAVE_H264")
set(H264_LIBS "WIN") # may be LIBAV in the future
set(H264_LIBRARIES ole32 mfplat mfuuid wmcodecdspuuid)

set(CMAKE_REQUIRED_LIBRARIES ${H264_LIBRARIES})
check_variable_exists(CLSID_VideoProcessorMFT HAVE_VIDEO_PROCESSOR_MFT)
set(CMAKE_REQUIRED_LIBRARIES)
if(HAVE_VIDEO_PROCESSOR_MFT)
add_definitions("-DHAVE_VIDEO_PROCESSOR_MFT")
endif()
else()
find_package(Ffmpeg)
if (AVCODEC_FOUND AND AVUTIL_FOUND AND SWSCALE_FOUND)
Expand Down
4 changes: 2 additions & 2 deletions common/network/Socket.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ void Socket::setFd(int fd)
isShutdown_ = false;
}

SocketListener::SocketListener(int fd)
: fd(fd), filter(nullptr)
SocketListener::SocketListener(int fd_)
: fd(fd_), filter(nullptr)
{
initSockets();
}
Expand Down
4 changes: 2 additions & 2 deletions common/network/TcpSocket.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ TcpListener::TcpListener(const struct sockaddr *listenaddr,
listen(sock);
}

Socket* TcpListener::createSocket(int fd) {
return new TcpSocket(fd);
Socket* TcpListener::createSocket(int fd_) {
return new TcpSocket(fd_);
}

std::list<std::string> TcpListener::getMyAddresses() {
Expand Down
4 changes: 2 additions & 2 deletions common/network/UnixSocket.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ UnixListener::~UnixListener()
unlink(addr.sun_path);
}

Socket* UnixListener::createSocket(int fd) {
return new UnixSocket(fd);
Socket* UnixListener::createSocket(int fd_) {
return new UnixSocket(fd_);
}

int UnixListener::getMyPort() {
Expand Down
4 changes: 2 additions & 2 deletions common/os/Mutex.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ void Mutex::unlock()
#endif
}

Condition::Condition(Mutex* mutex)
Condition::Condition(Mutex* mutex_)
{
this->mutex = mutex;
this->mutex = mutex_;

#ifdef WIN32
systemCondition = new CONDITION_VARIABLE;
Expand Down
12 changes: 6 additions & 6 deletions common/rdr/AESInStream.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ bool AESInStream::fillBuffer()
{
if (!in->hasData(2))
return false;
const uint8_t* ptr = in->getptr(2);
size_t length = ((int)ptr[0] << 8) | (int)ptr[1];
const uint8_t* buf = in->getptr(2);
size_t length = ((int)buf[0] << 8) | (int)buf[1];
if (!in->hasData(2 + length + 16))
return false;
ensureSpace(length);
ptr = in->getptr(2 + length + 16);
const uint8_t* ad = ptr;
const uint8_t* data = ptr + 2;
const uint8_t* mac = ptr + 2 + length;
buf = in->getptr(2 + length + 16);
const uint8_t* ad = buf;
const uint8_t* data = buf + 2;
const uint8_t* mac = buf + 2 + length;
uint8_t macComputed[16];

if (keySize == 128) {
Expand Down
4 changes: 2 additions & 2 deletions common/rdr/BufferedOutStream.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ using namespace rdr;
static const size_t DEFAULT_BUF_SIZE = 16384;
static const size_t MAX_BUF_SIZE = 32 * 1024 * 1024;

BufferedOutStream::BufferedOutStream(bool emulateCork)
: bufSize(DEFAULT_BUF_SIZE), offset(0), emulateCork(emulateCork)
BufferedOutStream::BufferedOutStream(bool emulateCork_)
: bufSize(DEFAULT_BUF_SIZE), offset(0), emulateCork(emulateCork_)
{
ptr = start = sentUpTo = new uint8_t[bufSize];
end = start + bufSize;
Expand Down
4 changes: 2 additions & 2 deletions common/rdr/Exception.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ Exception::Exception(const char *format, ...) {
va_end(ap);
}

GAIException::GAIException(const char* s, int err)
: Exception("%s", s)
GAIException::GAIException(const char* s, int err_)
: Exception("%s", s), err(err_)
{
strncat(str_, ": ", len-1-strlen(str_));
#ifdef _WIN32
Expand Down
4 changes: 2 additions & 2 deletions common/rfb/CConnection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ void CConnection::sendClipboardData(const char* data)
// FIXME: This conversion magic should be in CMsgWriter
std::string filtered(convertCRLF(data));
size_t sizes[1] = { filtered.size() + 1 };
const uint8_t* data[1] = { (const uint8_t*)filtered.c_str() };
const uint8_t* datas[1] = { (const uint8_t*)filtered.c_str() };

if (unsolicitedClipboardAttempt) {
unsolicitedClipboardAttempt = false;
Expand All @@ -687,7 +687,7 @@ void CConnection::sendClipboardData(const char* data)
}
}

writer()->writeClipboardProvide(rfb::clipboardUTF8, sizes, data);
writer()->writeClipboardProvide(rfb::clipboardUTF8, sizes, datas);
} else {
writer()->writeClientCutText(data);
}
Expand Down
12 changes: 6 additions & 6 deletions common/rfb/CMsgReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -827,31 +827,31 @@ bool CMsgReader::readExtendedDesktopSize(int x, int y, int w, int h)

bool CMsgReader::readLEDState()
{
uint8_t state;
uint8_t ledState;

if (!is->hasData(1))
return false;

state = is->readU8();
ledState = is->readU8();

handler->setLEDState(state);
handler->setLEDState(ledState);

return true;
}

bool CMsgReader::readVMwareLEDState()
{
uint32_t state;
uint32_t ledState;

if (!is->hasData(4))
return false;

state = is->readU32();
ledState = is->readU32();

// As luck has it, this extension uses the same bit definitions,
// so no conversion required

handler->setLEDState(state);
handler->setLEDState(ledState);

return true;
}
4 changes: 2 additions & 2 deletions common/rfb/CSecurityDH.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ using namespace rfb;
const int MinKeyLength = 128;
const int MaxKeyLength = 1024;

CSecurityDH::CSecurityDH(CConnection* cc)
: CSecurity(cc), keyLength(0)
CSecurityDH::CSecurityDH(CConnection* cc_)
: CSecurity(cc_), keyLength(0)
{
mpz_init(g);
mpz_init(p);
Expand Down
4 changes: 2 additions & 2 deletions common/rfb/CSecurityMSLogonII.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@

using namespace rfb;

CSecurityMSLogonII::CSecurityMSLogonII(CConnection* cc)
: CSecurity(cc)
CSecurityMSLogonII::CSecurityMSLogonII(CConnection* cc_)
: CSecurity(cc_)
{
mpz_init(g);
mpz_init(p);
Expand Down
2 changes: 1 addition & 1 deletion common/rfb/CSecurityNone.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace rfb {

class CSecurityNone : public CSecurity {
public:
CSecurityNone(CConnection* cc) : CSecurity(cc) {}
CSecurityNone(CConnection* cc_) : CSecurity(cc_) {}
bool processMsg() override { return true; }
int getType() const override {return secTypeNone;}
};
Expand Down
2 changes: 1 addition & 1 deletion common/rfb/CSecurityPlain.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace rfb {

class CSecurityPlain : public CSecurity {
public:
CSecurityPlain(CConnection* cc) : CSecurity(cc) {}
CSecurityPlain(CConnection* cc_) : CSecurity(cc_) {}
bool processMsg() override;
int getType() const override { return secTypePlain; }
};
Expand Down
4 changes: 2 additions & 2 deletions common/rfb/CSecurityRSAAES.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ const int MaxKeyLength = 8192;

using namespace rfb;

CSecurityRSAAES::CSecurityRSAAES(CConnection* cc, uint32_t _secType,
CSecurityRSAAES::CSecurityRSAAES(CConnection* cc_, uint32_t _secType,
int _keySize, bool _isAllEncrypted)
: CSecurity(cc), state(ReadPublicKey),
: CSecurity(cc_), state(ReadPublicKey),
keySize(_keySize), isAllEncrypted(_isAllEncrypted), secType(_secType),
clientKey(), clientPublicKey(), serverKey(),
serverKeyN(nullptr), serverKeyE(nullptr),
Expand Down
4 changes: 2 additions & 2 deletions common/rfb/CSecurityStack.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

using namespace rfb;

CSecurityStack::CSecurityStack(CConnection* cc, int Type,
CSecurityStack::CSecurityStack(CConnection* cc_, int Type,
CSecurity* s0, CSecurity* s1)
: CSecurity(cc), type(Type)
: CSecurity(cc_), type(Type)
{
state = 0;
state0 = s0;
Expand Down
4 changes: 2 additions & 2 deletions common/rfb/CSecurityTLS.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ static const char* configdirfn(const char* fn)
return full_path;
}

CSecurityTLS::CSecurityTLS(CConnection* cc, bool _anon)
: CSecurity(cc), session(nullptr),
CSecurityTLS::CSecurityTLS(CConnection* cc_, bool _anon)
: CSecurity(cc_), session(nullptr),
anon_cred(nullptr), cert_cred(nullptr),
anon(_anon), tlsis(nullptr), tlsos(nullptr),
rawis(nullptr), rawos(nullptr)
Expand Down
5 changes: 3 additions & 2 deletions common/rfb/CSecurityVeNCrypt.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ using namespace std;

static LogWriter vlog("CVeNCrypt");

CSecurityVeNCrypt::CSecurityVeNCrypt(CConnection* cc, SecurityClient* sec)
: CSecurity(cc), csecurity(nullptr), security(sec)
CSecurityVeNCrypt::CSecurityVeNCrypt(CConnection* cc_,
SecurityClient* sec)
: CSecurity(cc_), csecurity(nullptr), security(sec)
{
haveRecvdMajorVersion = false;
haveRecvdMinorVersion = false;
Expand Down
2 changes: 1 addition & 1 deletion common/rfb/CSecurityVncAuth.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace rfb {

class CSecurityVncAuth : public CSecurity {
public:
CSecurityVncAuth(CConnection* cc) : CSecurity(cc) {}
CSecurityVncAuth(CConnection* cc_) : CSecurity(cc_) {}
virtual ~CSecurityVncAuth() {}
bool processMsg() override;
int getType() const override {return secTypeVncAuth;};
Expand Down
6 changes: 3 additions & 3 deletions common/rfb/Configuration.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ bool Configuration::set(const char* n, const char* v, bool immutable) {
return set(n, strlen(n), v, immutable);
}

bool Configuration::set(const char* name, int len,
bool Configuration::set(const char* paramName, int len,
const char* val, bool immutable)
{
VoidParameter* current = head;
while (current) {
if ((int)strlen(current->getName()) == len &&
strncasecmp(current->getName(), name, len) == 0)
strncasecmp(current->getName(), paramName, len) == 0)
{
bool b = current->setParam(val);
if (b && immutable)
Expand All @@ -91,7 +91,7 @@ bool Configuration::set(const char* name, int len,
}
current = current->_next;
}
return _next ? _next->set(name, len, val, immutable) : false;
return _next ? _next->set(paramName, len, val, immutable) : false;
}

bool Configuration::set(const char* config, bool immutable) {
Expand Down
6 changes: 3 additions & 3 deletions common/rfb/Cursor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ using namespace rfb;
static LogWriter vlog("Cursor");

Cursor::Cursor(int width, int height, const Point& hotspot,
const uint8_t* data) :
const uint8_t* data_) :
width_(width), height_(height), hotspot_(hotspot)
{
this->data = new uint8_t[width_*height_*4];
memcpy(this->data, data, width_*height_*4);
data = new uint8_t[width_*height_*4];
memcpy(data, data_, width_*height_*4);
}

Cursor::Cursor(const Cursor& other) :
Expand Down
11 changes: 4 additions & 7 deletions common/rfb/DecodeManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ using namespace rfb;

static LogWriter vlog("DecodeManager");

DecodeManager::DecodeManager(CConnection *conn) :
conn(conn), threadException(nullptr)
DecodeManager::DecodeManager(CConnection *conn_) :
conn(conn_), threadException(nullptr)
{
size_t cpuCount;

Expand Down Expand Up @@ -268,12 +268,9 @@ void DecodeManager::throwThreadException()
throw e;
}

DecodeManager::DecodeThread::DecodeThread(DecodeManager* manager)
DecodeManager::DecodeThread::DecodeThread(DecodeManager* manager_)
: manager(manager_), stopRequested(false)
{
this->manager = manager;

stopRequested = false;

start();
}

Expand Down
2 changes: 1 addition & 1 deletion common/rfb/Decoder.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

using namespace rfb;

Decoder::Decoder(enum DecoderFlags flags) : flags(flags)
Decoder::Decoder(enum DecoderFlags flags_) : flags(flags_)
{
}

Expand Down
10 changes: 5 additions & 5 deletions common/rfb/H264Decoder.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ bool H264Decoder::readRect(const Rect& /*r*/,

len = is->readU32();
os->writeU32(len);
uint32_t flags = is->readU32();
uint32_t reset = is->readU32();

os->writeU32(flags);
os->writeU32(reset);

if (!is->hasDataOrRestore(len))
return false;
Expand All @@ -100,15 +100,15 @@ void H264Decoder::decodeRect(const Rect& r, const uint8_t* buffer,
{
rdr::MemInStream is(buffer, buflen);
uint32_t len = is.readU32();
uint32_t flags = is.readU32();
uint32_t reset = is.readU32();

H264DecoderContext* ctx = nullptr;
if (flags & resetAllContexts)
if (reset & resetAllContexts)
{
resetContexts();
if (!len)
return;
flags &= ~(resetContext | resetAllContexts);
reset &= ~(resetContext | resetAllContexts);
} else {
ctx = findContext(r);
}
Expand Down
Loading

0 comments on commit 12b3f40

Please sign in to comment.