From: Pierre Ossman Date: Thu, 17 Nov 2022 14:32:48 +0000 (+0100) Subject: Clean up BinaryParameter typing X-Git-Tag: v1.13.90~87^2~30 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cf931f8c9a677161bde70859799f1ad4f3470fbc;p=tigervnc.git Clean up BinaryParameter typing This is explicitly a byte sequence, so let's try to keep a consistent typing. --- diff --git a/common/rfb/Configuration.cxx b/common/rfb/Configuration.cxx index 350582f0..c2f59d86 100644 --- a/common/rfb/Configuration.cxx +++ b/common/rfb/Configuration.cxx @@ -1,6 +1,7 @@ /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. * Copyright 2004-2005 Cendio AB. * Copyright 2017 Peter Astrand for Cendio AB + * Copyright 2011-2022 Pierre Ossman for Cendio AB * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,6 +25,7 @@ #include #endif +#include #include #include #include @@ -420,13 +422,14 @@ StringParameter::operator const char *() const { // -=- BinaryParameter BinaryParameter::BinaryParameter(const char* name_, const char* desc_, - const void* v, size_t l, ConfigurationObject co) + const uint8_t* v, size_t l, ConfigurationObject co) : VoidParameter(name_, desc_, co), value(0), length(0), def_value(0), def_length(0) { if (l) { - value = new char[l]; + assert(v); + value = new uint8_t[l]; length = l; memcpy(value, v, l); - def_value = new char[l]; + def_value = new uint8_t[l]; def_length = l; memcpy(def_value, v, l); } @@ -442,39 +445,40 @@ bool BinaryParameter::setParam(const char* v) { vlog.debug("set %s(Binary) to %s", getName(), v); delete [] value; length = 0; - value = (char*)hexToBin(v, strlen(v)); + value = hexToBin(v, strlen(v)); if (value == NULL) return false; length = strlen(v)/2; return true; } -void BinaryParameter::setParam(const void* v, size_t len) { +void BinaryParameter::setParam(const uint8_t* v, size_t len) { LOCK_CONFIG; if (immutable) return; vlog.debug("set %s(Binary)", getName()); delete [] value; value = 0; if (len) { - value = new char[len]; + assert(v); + value = new uint8_t[len]; length = len; memcpy(value, v, len); } } char* BinaryParameter::getDefaultStr() const { - return binToHex((const uint8_t*)def_value, def_length); + return binToHex(def_value, def_length); } char* BinaryParameter::getValueStr() const { LOCK_CONFIG; - return binToHex((const uint8_t*)value, length); + return binToHex(value, length); } -void BinaryParameter::getData(void** data_, size_t* length_) const { +void BinaryParameter::getData(uint8_t** data_, size_t* length_) const { LOCK_CONFIG; if (length_) *length_ = length; if (data_) { - *data_ = new char[length]; + *data_ = new uint8_t[length]; memcpy(*data_, value, length); } } diff --git a/common/rfb/Configuration.h b/common/rfb/Configuration.h index 396e40dd..9e86dcc9 100644 --- a/common/rfb/Configuration.h +++ b/common/rfb/Configuration.h @@ -1,4 +1,5 @@ /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. + * Copyright 2011-2022 Pierre Ossman for Cendio AB * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -256,23 +257,23 @@ namespace rfb { class BinaryParameter : public VoidParameter { public: BinaryParameter(const char* name_, const char* desc_, - const void* v, size_t l, + const uint8_t* v, size_t l, ConfigurationObject co=ConfGlobal); using VoidParameter::setParam; virtual ~BinaryParameter(); virtual bool setParam(const char* value); - virtual void setParam(const void* v, size_t l); + virtual void setParam(const uint8_t* v, size_t l); virtual char* getDefaultStr() const; virtual char* getValueStr() const; // getData() will return length zero if there is no data // NB: data may be set to zero, OR set to a zero-length buffer - void getData(void** data, size_t* length) const; + void getData(uint8_t** data, size_t* length) const; protected: - char* value; + uint8_t* value; size_t length; - char* def_value; + uint8_t* def_value; size_t def_length; }; diff --git a/common/rfb/SSecurityVncAuth.cxx b/common/rfb/SSecurityVncAuth.cxx index 380b4f4c..b70f0668 100644 --- a/common/rfb/SSecurityVncAuth.cxx +++ b/common/rfb/SSecurityVncAuth.cxx @@ -123,7 +123,7 @@ VncAuthPasswdParameter::VncAuthPasswdParameter(const char* name, void VncAuthPasswdParameter::getVncAuthPasswd(PlainPasswd *password, PlainPasswd *readOnlyPassword) { ObfuscatedPasswd obfuscated, obfuscatedReadOnly; - getData((void**)&obfuscated.buf, &obfuscated.length); + getData((uint8_t**)&obfuscated.buf, &obfuscated.length); if (obfuscated.length == 0) { if (passwdFile) {