diff options
author | Pierre Ossman <ossman@cendio.se> | 2023-01-10 14:30:37 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2023-02-04 14:03:13 +0100 |
commit | 337dbc392253af92b0577da062a5abc1d032b1ef (patch) | |
tree | e540dc7dc861f575d841970561651a9fac506120 /win/vncconfig/Connections.h | |
parent | dde95fccca9fffff0da2dc486d639b162115bb9e (diff) | |
download | tigervnc-337dbc392253af92b0577da062a5abc1d032b1ef.tar.gz tigervnc-337dbc392253af92b0577da062a5abc1d032b1ef.zip |
Return std::string instead of dynamic allocations
We mostly use classical C strings, but the memory management around them
can get confusing and error prone. Let's use std::string for the cases
where we need to return a newly allocated string.
Diffstat (limited to 'win/vncconfig/Connections.h')
-rw-r--r-- | win/vncconfig/Connections.h | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/win/vncconfig/Connections.h b/win/vncconfig/Connections.h index fbf46ec1..f9b66547 100644 --- a/win/vncconfig/Connections.h +++ b/win/vncconfig/Connections.h @@ -73,7 +73,7 @@ namespace rfb { try { network::TcpFilter::Pattern pat(network::TcpFilter::parsePattern(newPat.buf)); - pattern.replaceBuf(CharArray(network::TcpFilter::patternToStr(pat)).takeBuf()); + pattern.replaceBuf(strDup(network::TcpFilter::patternToStr(pat).c_str())); } catch(rdr::Exception& e) { MsgBox(NULL, e.str(), MB_ICONEXCLAMATION | MB_OK); return false; @@ -101,7 +101,7 @@ namespace rfb { SendMessage(listBox, LB_DELETESTRING, 0, 0); CharArray tmp; - tmp.buf = hosts.getData(); + tmp.buf = strDup(hosts.getValueStr().c_str()); while (tmp.buf) { CharArray first; strSplit(tmp.buf, ',', &first.buf, &tmp.buf); @@ -228,13 +228,13 @@ namespace rfb { regKey.setInt("PortNumber", isItemChecked(IDC_RFB_ENABLE) ? getItemInt(IDC_PORT) : 0); regKey.setInt("IdleTimeout", getItemInt(IDC_IDLE_TIMEOUT)); regKey.setInt("LocalHost", isItemChecked(IDC_LOCALHOST)); - regKey.setString("Hosts", CharArray(getHosts()).buf); + regKey.setString("Hosts", getHosts().c_str()); return true; } bool isChanged() { try { - CharArray new_hosts(getHosts()); - return (strcmp(new_hosts.buf, hosts) != 0) || + std::string new_hosts = getHosts(); + return (new_hosts != (const char*)hosts) || (localHost != isItemChecked(IDC_LOCALHOST)) || (port_number != getItemInt(IDC_PORT)) || (rfb::Server::idleTimeout != getItemInt(IDC_IDLE_TIMEOUT)); @@ -242,21 +242,21 @@ namespace rfb { return false; } } - char* getHosts() { + std::string getHosts() { int bufLen = 1, i; HWND listBox = GetDlgItem(handle, IDC_HOSTS); for (i=0; i<SendMessage(listBox, LB_GETCOUNT, 0, 0); i++) bufLen+=SendMessage(listBox, LB_GETTEXTLEN, i, 0)+1; - CharArray hosts_str(bufLen); - hosts_str.buf[0] = 0; - char* outPos = hosts_str.buf; + std::vector<char> hosts_str(bufLen); + hosts_str[0] = 0; + char* outPos = hosts_str.data(); for (i=0; i<SendMessage(listBox, LB_GETCOUNT, 0, 0); i++) { outPos += SendMessage(listBox, LB_GETTEXT, i, (LPARAM)outPos); outPos[0] = ','; outPos[1] = 0; outPos++; } - return strDup(hosts_str.buf); + return hosts_str.data(); } protected: |