From: Adam Tkac Date: Fri, 4 Sep 2009 10:57:20 +0000 (+0000) Subject: Revert previous commit (r3889). Windows code has to be cleaned before this X-Git-Tag: v1.0.90~389 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d36b626bbb7b90306d3d93a5b82fd117fe8ec15f;p=tigervnc.git Revert previous commit (r3889). Windows code has to be cleaned before this change. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@3890 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx index 7056a080..7ceff0b0 100644 --- a/common/network/TcpSocket.cxx +++ b/common/network/TcpSocket.cxx @@ -238,9 +238,9 @@ char* TcpSocket::getMyAddress() { char* name = inet_ntoa(addr); if (name) { - return safe_strdup(name); + return rfb::strDup(name); } else { - return safe_strdup(""); + return rfb::strDup(""); } } @@ -268,9 +268,9 @@ char* TcpSocket::getPeerAddress() { char* name = inet_ntoa(addr); if (name) { - return safe_strdup(name); + return rfb::strDup(name); } else { - return safe_strdup(""); + return rfb::strDup(""); } } @@ -451,7 +451,7 @@ int TcpListener::getMyPort() { TcpFilter::TcpFilter(const char* spec) { rfb::CharArray tmp; - tmp.buf = safe_strdup(spec); + tmp.buf = rfb::strDup(spec); while (tmp.buf) { rfb::CharArray first; rfb::strSplit(tmp.buf, ',', &first.buf, &tmp.buf); @@ -541,9 +541,9 @@ char* TcpFilter::patternToStr(const TcpFilter::Pattern& p) { in_addr tmp; rfb::CharArray addr, mask; tmp.s_addr = p.address; - addr.buf = safe_strdup(inet_ntoa(tmp)); + addr.buf = rfb::strDup(inet_ntoa(tmp)); tmp.s_addr = p.mask; - mask.buf = safe_strdup(inet_ntoa(tmp)); + mask.buf = rfb::strDup(inet_ntoa(tmp)); char* result = new char[strlen(addr.buf)+1+strlen(mask.buf)+1+1]; switch (p.action) { case Accept: result[0] = '+'; break; diff --git a/common/rfb/Blacklist.cxx b/common/rfb/Blacklist.cxx index 1db2995c..4590befe 100644 --- a/common/rfb/Blacklist.cxx +++ b/common/rfb/Blacklist.cxx @@ -17,7 +17,6 @@ */ #include #include -#include using namespace rfb; @@ -38,7 +37,7 @@ Blacklist::~Blacklist() { // Free the map keys BlacklistMap::iterator i; for (i=blm.begin(); i!=blm.end(); i++) { - free((void *)(*i).first); + strFree((char*)(*i).first); } } @@ -52,7 +51,7 @@ bool Blacklist::isBlackmarked(const char* name) { bi.marks = 1; bi.blockUntil = 0; bi.blockTimeout = initialTimeout; - blm[safe_strdup(name)] = bi; + blm[strDup(name)] = bi; i = blm.find(name); } @@ -81,7 +80,7 @@ bool Blacklist::isBlackmarked(const char* name) { void Blacklist::clearBlackmark(const char* name) { BlacklistMap::iterator i = blm.find(name); if (i != blm.end()) { - free((void *)(*i).first); + strFree((char*)(*i).first); blm.erase(i); } } diff --git a/common/rfb/CConnection.cxx b/common/rfb/CConnection.cxx index 59955696..36778f02 100644 --- a/common/rfb/CConnection.cxx +++ b/common/rfb/CConnection.cxx @@ -234,7 +234,7 @@ void CConnection::processSecurityResultMsg() } CharArray reason; if (cp.beforeVersion(3,8)) - reason.buf = safe_strdup("Authentication failure"); + reason.buf = strDup("Authentication failure"); else reason.buf = is->readString(); state_ = RFBSTATE_INVALID; diff --git a/common/rfb/CConnection.h b/common/rfb/CConnection.h index b3fd093f..79110eb9 100644 --- a/common/rfb/CConnection.h +++ b/common/rfb/CConnection.h @@ -47,7 +47,7 @@ namespace rfb { // which we are connected. This might be the result of getPeerEndpoint on // a TcpSocket, for example, or a host specified by DNS name & port. // The serverName is used when verifying the Identity of a host (see RA2). - void setServerName(const char* name_) { serverName.replaceBuf(safe_strdup(name_)); } + void setServerName(const char* name_) { serverName.replaceBuf(strDup(name_)); } // setStreams() sets the streams to be used for the connection. These must // be set before initialiseProtocol() and processMsg() are called. The diff --git a/common/rfb/Configuration.cxx b/common/rfb/Configuration.cxx index fd4c23ae..9ebc20a8 100644 --- a/common/rfb/Configuration.cxx +++ b/common/rfb/Configuration.cxx @@ -67,7 +67,7 @@ Configuration* Configuration::global() { // -=- Configuration implementation Configuration::Configuration(const char* name_, Configuration* attachToGroup) -: name(safe_strdup(name_)), head(0), _next(0) { +: name(strDup(name_)), head(0), _next(0) { if (attachToGroup) { _next = attachToGroup->_next; attachToGroup->_next = this; @@ -182,7 +182,7 @@ void Configuration::list(int width, int nameWidth) { if (column + (int)strlen(def_str) + 11 > width) fprintf(stderr,"\n%*s",nameWidth+4,""); fprintf(stderr," (default=%s)\n",def_str); - free(def_str); + strFree(def_str); } else { fprintf(stderr,"\n"); } @@ -315,11 +315,11 @@ void BoolParameter::setParam(bool b) { char* BoolParameter::getDefaultStr() const { - return safe_strdup(def_value ? "1" : "0"); + return strDup(def_value ? "1" : "0"); } char* BoolParameter::getValueStr() const { - return safe_strdup(value ? "1" : "0"); + return strDup(value ? "1" : "0"); } bool BoolParameter::isBool() const { @@ -381,7 +381,7 @@ IntParameter::operator int() const { StringParameter::StringParameter(const char* name_, const char* desc_, const char* v, Configuration* conf) - : VoidParameter(name_, desc_, conf), value(safe_strdup(v)), def_value(v) + : VoidParameter(name_, desc_, conf), value(strDup(v)), def_value(v) { if (!v) { fprintf(stderr,"Default value for %s not allowed\n",name_); @@ -390,7 +390,7 @@ StringParameter::StringParameter(const char* name_, const char* desc_, } StringParameter::~StringParameter() { - free(value); + strFree(value); } bool StringParameter::setParam(const char* v) { @@ -400,17 +400,17 @@ bool StringParameter::setParam(const char* v) { throw rfb::Exception("setParam() not allowed"); vlog.debug("set %s(String) to %s", getName(), v); CharArray oldValue(value); - value = safe_strdup(v); + value = strDup(v); return value != 0; } char* StringParameter::getDefaultStr() const { - return safe_strdup(def_value); + return strDup(def_value); } char* StringParameter::getValueStr() const { LOCK_CONFIG; - return safe_strdup(value); + return strDup(value); } // -=- BinaryParameter diff --git a/common/rfb/ConnParams.cxx b/common/rfb/ConnParams.cxx index 4bbd2cbe..7b27a734 100644 --- a/common/rfb/ConnParams.cxx +++ b/common/rfb/ConnParams.cxx @@ -82,7 +82,7 @@ void ConnParams::setPF(const PixelFormat& pf) void ConnParams::setName(const char* name) { delete [] name_; - name_ = safe_strdup(name); + name_ = strDup(name); } void ConnParams::setEncodings(int nEncodings, const rdr::U32* encodings) diff --git a/common/rfb/HTTPServer.cxx b/common/rfb/HTTPServer.cxx index 934ca74e..94f06090 100644 --- a/common/rfb/HTTPServer.cxx +++ b/common/rfb/HTTPServer.cxx @@ -240,7 +240,7 @@ HTTPServer::Session::processHTTP() { return writeResponse(501); // Store the URI to the "document" - uri.buf = safe_strdup(path); + uri.buf = strDup(path); } // Move on to reading the request headers diff --git a/common/rfb/Hostname.h b/common/rfb/Hostname.h index d7ff664e..ebdf816f 100644 --- a/common/rfb/Hostname.h +++ b/common/rfb/Hostname.h @@ -32,7 +32,7 @@ namespace rfb { if (!strSplit(&hi[1], ']', &hostBuf.buf, &portBuf.buf)) throw rdr::Exception("unmatched [ in host"); } else { - portBuf.buf = safe_strdup(hi); + portBuf.buf = strDup(hi); } if (strSplit(portBuf.buf, ':', hostBuf.buf ? 0 : &hostBuf.buf, &portBuf.buf)) { if (portBuf.buf[0] == ':') { @@ -45,7 +45,7 @@ namespace rfb { *port = basePort; } if (strlen(hostBuf.buf) == 0) - *host = safe_strdup("localhost"); + *host = strDup("localhost"); else *host = hostBuf.takeBuf(); } diff --git a/common/rfb/ListConnInfo.h b/common/rfb/ListConnInfo.h index 6e4eacc5..cabcbc79 100644 --- a/common/rfb/ListConnInfo.h +++ b/common/rfb/ListConnInfo.h @@ -52,8 +52,8 @@ namespace rfb { void addInfo(void* Conn, char* IP, char* Time, int Status) { conn.push_back(Conn); - IP_address.push_back(safe_strdup(IP)); - time_conn.push_back(safe_strdup(Time)); + IP_address.push_back(strDup(IP)); + time_conn.push_back(strDup(Time)); status.push_back(Status); } @@ -62,16 +62,16 @@ namespace rfb { buf[1] = *ti; switch (*si) { case 0: - buf[2] = safe_strdup("Full control"); + buf[2] = strDup("Full control"); break; case 1: - buf[2] = safe_strdup("View only"); + buf[2] = strDup("View only"); break; case 2: - buf[2] = safe_strdup("Stop updating"); + buf[2] = strDup("Stop updating"); break; default: - buf[2] = safe_strdup("Unknown"); + buf[2] = strDup("Unknown"); } } diff --git a/common/rfb/Logger_file.cxx b/common/rfb/Logger_file.cxx index cf195c0d..8a109e4a 100644 --- a/common/rfb/Logger_file.cxx +++ b/common/rfb/Logger_file.cxx @@ -97,7 +97,7 @@ void Logger_File::write(int level, const char *logname, const char *message) void Logger_File::setFilename(const char* filename) { closeFile(); - m_filename = safe_strdup(filename); + m_filename = strDup(filename); } void Logger_File::setFile(FILE* file) @@ -113,7 +113,7 @@ void Logger_File::closeFile() fclose(m_file); m_file = 0; } - free(m_filename); + strFree(m_filename); m_filename = 0; } } diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx index 0006ff20..e286cf31 100644 --- a/common/rfb/VNCSConnectionST.cxx +++ b/common/rfb/VNCSConnectionST.cxx @@ -89,7 +89,7 @@ void VNCSConnectionST::close(const char* reason) { // Log the reason for the close if (!closeReason.buf) - closeReason.buf = safe_strdup(reason); + closeReason.buf = strDup(reason); else vlog.debug("second close: %s (%s)", peerEndpoint.buf, reason); diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index 5be63969..a21526ad 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -74,7 +74,7 @@ static SSecurityFactoryStandard defaultSecurityFactory; VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_, SSecurityFactory* sf) : blHosts(&blacklist), desktop(desktop_), desktopStarted(false), pb(0), - name(safe_strdup(name_)), pointerClient(0), comparer(0), + name(strDup(name_)), pointerClient(0), comparer(0), renderedCursorInvalid(false), securityFactory(sf ? sf : &defaultSecurityFactory), queryConnectionHandler(0), keyRemapper(&KeyRemapper::defInstance), @@ -363,7 +363,7 @@ void VNCServerST::serverCutText(const char* str, int len) void VNCServerST::setName(const char* name_) { - name.replaceBuf(safe_strdup(name_)); + name.replaceBuf(strDup(name_)); std::list::iterator ci, ci_next; for (ci = clients.begin(); ci != clients.end(); ci = ci_next) { ci_next = ci; ci_next++; diff --git a/common/rfb/secTypes.cxx b/common/rfb/secTypes.cxx index 9ea6a000..830d8444 100644 --- a/common/rfb/secTypes.cxx +++ b/common/rfb/secTypes.cxx @@ -62,7 +62,7 @@ bool rfb::secTypeEncrypts(int num) std::list rfb::parseSecTypes(const char* types_) { std::list result; - CharArray types(safe_strdup(types_)), type; + CharArray types(strDup(types_)), type; while (types.buf) { strSplit(types.buf, ',', &type.buf, &types.buf); int typeNum = secTypeNum(type.buf); diff --git a/common/rfb/util.cxx b/common/rfb/util.cxx index 7935a3a0..a50ea586 100644 --- a/common/rfb/util.cxx +++ b/common/rfb/util.cxx @@ -35,19 +35,6 @@ #endif #include -#include -#include -#include - -char* safe_strdup(const char* s) { - char *tmp; - - tmp = strdup(s); - if (tmp == NULL) { - perror("safe_strdup failed"); - exit(1); - } -}; // Provide strcasecmp() and/or strncasecmp() if absent on this system. @@ -142,6 +129,19 @@ strncasecmp(const char *s1, const char *s2, size_t n) namespace rfb { + char* strDup(const char* s) { + if (!s) return 0; + int l = strlen(s); + char* r = new char[l+1]; + memcpy(r, s, l+1); + return r; + }; + + void strFree(char* s) { + delete [] s; + } + + bool strSplit(const char* src, const char limiter, char** out1, char** out2, bool fromEnd) { CharArray out1old, out2old; if (out1) out1old.buf = *out1; @@ -167,7 +167,7 @@ namespace rfb { } i+=increment; } - if (out1) *out1 = safe_strdup(src); + if (out1) *out1 = strDup(src); if (out2) *out2 = 0; return false; } diff --git a/common/rfb/util.h b/common/rfb/util.h index 8bf54842..933df527 100644 --- a/common/rfb/util.h +++ b/common/rfb/util.h @@ -30,8 +30,6 @@ #include #include -char* safe_strdup(const char* s); - namespace rfb { // -=- Class to handle cleanup of arrays of characters @@ -54,6 +52,9 @@ namespace rfb { CharArray& operator=(const CharArray&); }; + char* strDup(const char* s); + void strFree(char* s); + // Returns true if split successful. Returns false otherwise. // ALWAYS *copies* first part of string to out1 buffer. // If limiter not found, leaves out2 alone (null) and just copies to out1. diff --git a/unix/tx/TXButton.h b/unix/tx/TXButton.h index 59a84303..b7472797 100644 --- a/unix/tx/TXButton.h +++ b/unix/tx/TXButton.h @@ -59,7 +59,7 @@ public: // setText() changes the text in the button. void setText(const char* text_) { - text.buf = safe_strdup(text_); + text.buf = rfb::strDup(text_); int textWidth = XTextWidth(defaultFS, text.buf, strlen(text.buf)); int textHeight = (defaultFS->ascent + defaultFS->descent); int newWidth = __rfbmax(width(), textWidth + xPad*2 + bevel*2); diff --git a/unix/tx/TXLabel.h b/unix/tx/TXLabel.h index ebb8403c..3d5200d6 100644 --- a/unix/tx/TXLabel.h +++ b/unix/tx/TXLabel.h @@ -47,7 +47,7 @@ public: // setText() changes the text in the label. void setText(const char* text_) { - text.buf = safe_strdup(text_); + text.buf = rfb::strDup(text_); lines = 0; int lineStart = 0; int textWidth = 0; diff --git a/unix/tx/TXMenu.cxx b/unix/tx/TXMenu.cxx index df57daf8..92712f55 100644 --- a/unix/tx/TXMenu.cxx +++ b/unix/tx/TXMenu.cxx @@ -56,7 +56,7 @@ inline int TXMenu::entryHeight(int i) void TXMenu::addEntry(const char* text_, long id_) { assert(nEntries < maxEntries); - text[nEntries] = safe_strdup(text_); + text[nEntries] = rfb::strDup(text_); checked[nEntries] = false; id[nEntries++] = id_; int tw = 0; diff --git a/unix/tx/TXWindow.cxx b/unix/tx/TXWindow.cxx index 1b695e5b..2b535df8 100644 --- a/unix/tx/TXWindow.cxx +++ b/unix/tx/TXWindow.cxx @@ -93,7 +93,7 @@ void TXWindow::init(Display* dpy, const char* defaultWindowClass_) static char tickBits[] = { 0x80, 0xc0, 0xe2, 0x76, 0x3e, 0x1c, 0x08, 0x00}; tick = XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), tickBits, tickSize, tickSize); - defaultWindowClass = safe_strdup(defaultWindowClass_); + defaultWindowClass = rfb::strDup(defaultWindowClass_); } void TXWindow::handleXEvents(Display* dpy) diff --git a/unix/vncviewer/CConn.cxx b/unix/vncviewer/CConn.cxx index efc3c335..8231f4c6 100644 --- a/unix/vncviewer/CConn.cxx +++ b/unix/vncviewer/CConn.cxx @@ -221,8 +221,8 @@ void CConn::getUserPasswd(char** user, char** password) PasswdDialog dlg(dpy, title.buf, !user); if (!dlg.show()) throw rfb::Exception("Authentication cancelled"); if (user) - *user = safe_strdup(dlg.userEntry.getText()); - *password = safe_strdup(dlg.passwdEntry.getText()); + *user = strDup(dlg.userEntry.getText()); + *password = strDup(dlg.passwdEntry.getText()); } diff --git a/unix/vncviewer/vncviewer.cxx b/unix/vncviewer/vncviewer.cxx index 203df9a9..4a47788e 100644 --- a/unix/vncviewer/vncviewer.cxx +++ b/unix/vncviewer/vncviewer.cxx @@ -218,7 +218,7 @@ interpretViaParam (char **gatewayHost, char **remoteHost, if (**vncServerName != '\0') *remoteHost = *vncServerName; - *gatewayHost = safe_strdup (via.getValueStr ()); + *gatewayHost = strDup (via.getValueStr ()); *vncServerName = new char[50]; sprintf (*vncServerName, "localhost::%d", localPort); } diff --git a/unix/x0vncserver/x0vncserver.cxx b/unix/x0vncserver/x0vncserver.cxx index 3e555ce2..ec2fd764 100644 --- a/unix/x0vncserver/x0vncserver.cxx +++ b/unix/x0vncserver/x0vncserver.cxx @@ -101,7 +101,7 @@ public: const char* userName, char** reason) { if (queryConnectSock) { - *reason = safe_strdup("Another connection is currently being queried."); + *reason = strDup("Another connection is currently being queried."); return VNCServerST::REJECT; } if (!userName) userName = "(anonymous)"; diff --git a/unix/xserver/hw/vnc/XserverDesktop.cc b/unix/xserver/hw/vnc/XserverDesktop.cc index e8e49494..66c92d29 100644 --- a/unix/xserver/hw/vnc/XserverDesktop.cc +++ b/unix/xserver/hw/vnc/XserverDesktop.cc @@ -219,7 +219,7 @@ void XserverDesktop::setFramebuffer(int w, int h, void* fbptr, int stride) char* XserverDesktop::substitute(const char* varName) { if (strcmp(varName, "$$") == 0) { - return safe_strdup("$"); + return rfb::strDup("$"); } if (strcmp(varName, "$PORT") == 0) { char* str = new char[10]; @@ -247,7 +247,7 @@ char* XserverDesktop::substitute(const char* varName) return str; } if (strcmp(varName, "$DESKTOP") == 0) { - return safe_strdup(server->getName()); + return rfb::strDup(server->getName()); } if (strcmp(varName, "$DISPLAY") == 0) { struct utsname uts; @@ -260,7 +260,7 @@ char* XserverDesktop::substitute(const char* varName) } if (strcmp(varName, "$USER") == 0) { struct passwd* user = getpwuid(getuid()); - return safe_strdup(user ? user->pw_name : "?"); + return rfb::strDup(user ? user->pw_name : "?"); } return 0; } @@ -270,13 +270,13 @@ XserverDesktop::queryConnection(network::Socket* sock, const char* userName, char** reason) { if (queryConnectId) { - *reason = safe_strdup("Another connection is currently being queried."); + *reason = strDup("Another connection is currently being queried."); return rfb::VNCServerST::REJECT; } queryConnectAddress.replaceBuf(sock->getPeerAddress()); if (!userName) userName = "(anonymous)"; - queryConnectUsername.replaceBuf(safe_strdup(userName)); + queryConnectUsername.replaceBuf(strDup(userName)); queryConnectId = sock; vncQueryConnect(this, sock); return rfb::VNCServerST::PENDING;