aboutsummaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2023-01-15 16:55:34 +0100
committerPierre Ossman <ossman@cendio.se>2023-02-04 14:03:13 +0100
commit2047dae22fb862ff43309ebb4fe2b9e7d6ce6153 (patch)
tree975687d97e31e677f827e0f586a349868e6a1e65 /win
parentea6afa9b791e3782455a829f97515fa721edd522 (diff)
downloadtigervnc-2047dae22fb862ff43309ebb4fe2b9e7d6ce6153.tar.gz
tigervnc-2047dae22fb862ff43309ebb4fe2b9e7d6ce6153.zip
Return std::vector instead of dynamic allocation
This makes memory management more clear and robust when using these helper functions.
Diffstat (limited to 'win')
-rw-r--r--win/rfb_win32/Registry.cxx20
-rw-r--r--win/rfb_win32/Registry.h4
-rw-r--r--win/vncconfig/Legacy.cxx7
3 files changed, 12 insertions, 19 deletions
diff --git a/win/rfb_win32/Registry.cxx b/win/rfb_win32/Registry.cxx
index cb4e6688..78879c3b 100644
--- a/win/rfb_win32/Registry.cxx
+++ b/win/rfb_win32/Registry.cxx
@@ -173,23 +173,17 @@ TCHAR* RegKey::getString(const TCHAR* valname, const TCHAR* def) const {
}
}
-void RegKey::getBinary(const TCHAR* valname, void** data, size_t* length) const {
+std::vector<uint8_t> RegKey::getBinary(const TCHAR* valname) const {
TCharArray hex(getRepresentation(valname));
- *data = hexToBin(CStr(hex.buf), strlen(CStr(hex.buf)));
- *length = strlen(CStr(hex.buf))/2;
- if (*data == NULL)
- throw rdr::Exception("getBinary failed");
+ return hexToBin(CStr(hex.buf), strlen(CStr(hex.buf)));
}
-void RegKey::getBinary(const TCHAR* valname, void** data, size_t* length, void* def, size_t deflen) const {
+std::vector<uint8_t> RegKey::getBinary(const TCHAR* valname, const uint8_t* def, size_t deflen) const {
try {
- getBinary(valname, data, length);
+ return getBinary(valname);
} catch(rdr::Exception&) {
- if (deflen) {
- *data = new char[deflen];
- memcpy(*data, def, deflen);
- } else
- *data = 0;
- *length = deflen;
+ std::vector<uint8_t> out(deflen);
+ memcpy(out.data(), def, deflen);
+ return out;
}
}
diff --git a/win/rfb_win32/Registry.h b/win/rfb_win32/Registry.h
index 2bb16911..3b87983b 100644
--- a/win/rfb_win32/Registry.h
+++ b/win/rfb_win32/Registry.h
@@ -78,8 +78,8 @@ namespace rfb {
TCHAR* getString(const TCHAR* valname) const;
TCHAR* getString(const TCHAR* valname, const TCHAR* def) const;
- void getBinary(const TCHAR* valname, void** data, size_t* length) const;
- void getBinary(const TCHAR* valname, void** data, size_t* length, void* def, size_t deflength) const;
+ std::vector<uint8_t> getBinary(const TCHAR* valname) const;
+ std::vector<uint8_t> getBinary(const TCHAR* valname, const uint8_t* def, size_t deflength) const;
int getInt(const TCHAR* valname) const;
int getInt(const TCHAR* valname, int def) const;
diff --git a/win/vncconfig/Legacy.cxx b/win/vncconfig/Legacy.cxx
index deba0ff3..3edfd4f7 100644
--- a/win/vncconfig/Legacy.cxx
+++ b/win/vncconfig/Legacy.cxx
@@ -19,7 +19,6 @@
#include <vncconfig/Legacy.h>
#include <rfb/LogWriter.h>
-#include <rfb/Password.h>
#include <rfb_win32/CurrentUser.h>
using namespace rfb;
@@ -212,9 +211,9 @@ void LegacyPage::LoadPrefs()
}
regKey.setInt(_T("QueryTimeout"), key.getInt(_T("QueryTimeout"), 10));
- ObfuscatedPasswd passwd;
- key.getBinary(_T("Password"), (void**)&passwd.buf, &passwd.length, 0, 0);
- regKey.setBinary(_T("Password"), passwd.buf, passwd.length);
+ std::vector<uint8_t> passwd;
+ passwd = key.getBinary(_T("Password"));
+ regKey.setBinary(_T("Password"), passwd.data(), passwd.size());
bool enableInputs = key.getBool(_T("InputsEnabled"), true);
regKey.setBool(_T("AcceptKeyEvents"), enableInputs);