From 3143bfa1545c2aa70781c5c780df7e66f123614f Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 23 Jan 2023 20:04:15 +0100 Subject: [PATCH] Use standard C string functions It's just confusing that we have our own variety that isn't compatible. --- common/rfb/util.cxx | 25 ------------------------- common/rfb/util.h | 9 --------- unix/tx/TXWindow.cxx | 4 ++-- unix/xserver/hw/vnc/RFBGlue.cc | 11 +++-------- unix/xserver/hw/vnc/RFBGlue.h | 2 -- unix/xserver/hw/vnc/vncSelection.c | 8 ++++---- 6 files changed, 9 insertions(+), 50 deletions(-) diff --git a/common/rfb/util.cxx b/common/rfb/util.cxx index 0df9e1e3..22918cf9 100644 --- a/common/rfb/util.cxx +++ b/common/rfb/util.cxx @@ -32,18 +32,6 @@ 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; - } - std::string strFormat(const char *fmt, ...) { va_list ap; @@ -91,19 +79,6 @@ namespace rfb { return out; } - bool strContains(const char* src, char c) { - int l=strlen(src); - for (int i=0; i strSplit(const char* src, const char delimiter); - // Returns true if src contains c - bool strContains(const char* src, char c); - - // Copies src to dest, up to specified length-1, and guarantees termination - void strCopy(char* dest, const char* src, int destlen); - // Conversion to and from a hex string void binToHex(const uint8_t* in, size_t inlen, char* out, size_t outlen); diff --git a/unix/tx/TXWindow.cxx b/unix/tx/TXWindow.cxx index a631fa66..ee097e45 100644 --- a/unix/tx/TXWindow.cxx +++ b/unix/tx/TXWindow.cxx @@ -26,11 +26,11 @@ #include #include "TXWindow.h" #include +#include #include #include #include #include -#include std::list windows; @@ -101,7 +101,7 @@ void TXWindow::init(Display* dpy, const char* defaultWindowClass_) static unsigned char tickBits[] = { 0x80, 0xc0, 0xe2, 0x76, 0x3e, 0x1c, 0x08, 0x00}; tick = XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), (char*)tickBits, tickSize, tickSize); - defaultWindowClass = rfb::strDup(defaultWindowClass_); + defaultWindowClass = strdup(defaultWindowClass_); } void TXWindow::handleXEvents(Display* dpy) diff --git a/unix/xserver/hw/vnc/RFBGlue.cc b/unix/xserver/hw/vnc/RFBGlue.cc index 6bf745fc..2fbc27ee 100644 --- a/unix/xserver/hw/vnc/RFBGlue.cc +++ b/unix/xserver/hw/vnc/RFBGlue.cc @@ -225,7 +225,7 @@ int vncIsTCPPortUsed(int port) char* vncConvertLF(const char* src, size_t bytes) { try { - return strDup(convertLF(src, bytes).c_str()); + return strdup(convertLF(src, bytes).c_str()); } catch (...) { return NULL; } @@ -234,7 +234,7 @@ char* vncConvertLF(const char* src, size_t bytes) char* vncLatin1ToUTF8(const char* src, size_t bytes) { try { - return strDup(latin1ToUTF8(src, bytes).c_str()); + return strdup(latin1ToUTF8(src, bytes).c_str()); } catch (...) { return NULL; } @@ -243,13 +243,8 @@ char* vncLatin1ToUTF8(const char* src, size_t bytes) char* vncUTF8ToLatin1(const char* src, size_t bytes) { try { - return strDup(utf8ToLatin1(src, bytes).c_str()); + return strdup(utf8ToLatin1(src, bytes).c_str()); } catch (...) { return NULL; } } - -void vncStrFree(char* str) -{ - strFree(str); -} diff --git a/unix/xserver/hw/vnc/RFBGlue.h b/unix/xserver/hw/vnc/RFBGlue.h index 9dd91eab..d2b2e8aa 100644 --- a/unix/xserver/hw/vnc/RFBGlue.h +++ b/unix/xserver/hw/vnc/RFBGlue.h @@ -53,8 +53,6 @@ char* vncConvertLF(const char* src, size_t bytes); char* vncLatin1ToUTF8(const char* src, size_t bytes); char* vncUTF8ToLatin1(const char* src, size_t bytes); -void vncStrFree(char* str); - #ifdef __cplusplus } #endif diff --git a/unix/xserver/hw/vnc/vncSelection.c b/unix/xserver/hw/vnc/vncSelection.c index 8cde6de5..1ed35149 100644 --- a/unix/xserver/hw/vnc/vncSelection.c +++ b/unix/xserver/hw/vnc/vncSelection.c @@ -425,7 +425,7 @@ static int vncConvertSelection(ClientPtr client, Atom selection, XA_STRING, 8, PropModeReplace, strlen(latin1), latin1, TRUE); - vncStrFree(latin1); + free(latin1); if (rc != Success) return rc; @@ -593,7 +593,7 @@ static void vncHandleSelection(Atom selection, Atom target, return; utf8 = vncLatin1ToUTF8(filtered, (size_t)-1); - vncStrFree(filtered); + free(filtered); if (utf8 == NULL) return; @@ -602,7 +602,7 @@ static void vncHandleSelection(Atom selection, Atom target, vncSendClipboardData(utf8); - vncStrFree(utf8); + free(utf8); } else if (target == xaUTF8_STRING) { char *filtered; @@ -620,7 +620,7 @@ static void vncHandleSelection(Atom selection, Atom target, vncSendClipboardData(filtered); - vncStrFree(filtered); + free(filtered); } } -- 2.39.5