[X2Go-Commits] [libx2goclient] 15/132: src/x2goclient-network-ssh.c: check parameter for validity and optimize code in x2goclient_network_ssh_sanitize_sockspec ().

git-admin at x2go.org git-admin at x2go.org
Fri Dec 3 15:26:29 CET 2021


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch master
in repository libx2goclient.

commit bfa2b8a183ff86a2e3ff9515971d15c471fc670f
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Fri Feb 19 07:01:15 2021 +0100

    src/x2goclient-network-ssh.c: check parameter for validity and optimize code in x2goclient_network_ssh_sanitize_sockspec ().
---
 src/x2goclient-network-ssh.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/x2goclient-network-ssh.c b/src/x2goclient-network-ssh.c
index c74dbb1..31cfa5c 100644
--- a/src/x2goclient-network-ssh.c
+++ b/src/x2goclient-network-ssh.c
@@ -410,11 +410,21 @@ static guint16 x2goclient_network_ssh_parse_sockspec_port (const GString * const
 static GString* x2goclient_network_ssh_sanitize_sockspec (const GString * const sockspec) {
   GString *ret = NULL;
 
-  gchar *sanitize_sockspec = g_strdup (sockspec->str);
-  g_strstrip (sanitize_sockspec);
-  ret = g_string_new (g_strstrip (sanitize_sockspec));
-  g_free (sanitize_sockspec);
-  sanitize_sockspec = NULL;
+  if ((sockspec) && (sockspec->str)) {
+    /*
+     * We can't really optimize this. g_strstrip () works in-place, so we'll
+     * have to create a copy of the original data anyway.
+     *
+     * It would be nice to avoid the third iteration updating the size, but
+     * that doesn't seem to be feasible without writing our private
+     * g_strstrip () implementation.
+     *
+     * Just don't over-optimize.
+     */
+    ret = g_string_new (sockspec->str);
+    (void) g_strstrip (ret->str);
+    (void) g_string_set_size (ret, strlen (ret->str));
+  }
 
   return (ret);
 }

--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/libx2goclient.git


More information about the x2go-commits mailing list