[vlc-commits] cli: simplify initialising Unix socket address

Rémi Denis-Courmont git at videolan.org
Sun Nov 29 14:56:07 CET 2020


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Nov 29 13:39:36 2020 +0200| [b80e1b77c87f6a1c946db440e72af279011f30c0] | committer: Rémi Denis-Courmont

cli: simplify initialising Unix socket address

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b80e1b77c87f6a1c946db440e72af279011f30c0
---

 modules/control/cli/cli.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/modules/control/cli/cli.c b/modules/control/cli/cli.c
index cc751495dd..4fd28c2ee8 100644
--- a/modules/control/cli/cli.c
+++ b/modules/control/cli/cli.c
@@ -812,19 +812,19 @@ static int Activate( vlc_object_t *p_this )
     if( psz_unix_path )
     {
         int i_socket;
-        struct sockaddr_un addr;
-
-        memset( &addr, 0, sizeof(struct sockaddr_un) );
+        struct sockaddr_un addr = { .sun_family = AF_LOCAL };
 
         msg_Dbg( p_intf, "trying UNIX socket" );
 
         /* The given unix path cannot be longer than sun_path - 1 to take into
          * account the terminated null character. */
-        if ( strlen(psz_unix_path) + 1 >= sizeof( addr.sun_path ) )
+        size_t len = strlen(psz_unix_path);
+        if (len >= sizeof (addr.sun_path))
         {
             msg_Err( p_intf, "rc-unix value is longer than expected" );
             goto error;
         }
+        memcpy(addr.sun_path, psz_unix_path, len + 1);
 
         if( (i_socket = vlc_socket( PF_LOCAL, SOCK_STREAM, 0, false ) ) < 0 )
         {
@@ -832,10 +832,6 @@ static int Activate( vlc_object_t *p_this )
             goto error;
         }
 
-        addr.sun_family = AF_LOCAL;
-        strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) - 1 );
-        addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
-
         if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr))
          && (errno == EADDRINUSE)
          && connect (i_socket, (struct sockaddr *)&addr, sizeof (addr))



More information about the vlc-commits mailing list