[vlc-commits] cli: drop variable-length array and extra CR

Rémi Denis-Courmont git at videolan.org
Sun Oct 18 20:26:06 CEST 2020


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Oct 18 21:24:54 2020 +0300| [030d9c6b35746b985f28df5d1db9cc1d57669cb9] | committer: Rémi Denis-Courmont

cli: drop variable-length array and extra CR

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

 modules/control/cli/cli.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/modules/control/cli/cli.c b/modules/control/cli/cli.c
index 5ec2d4d359..6c48b887ef 100644
--- a/modules/control/cli/cli.c
+++ b/modules/control/cli/cli.c
@@ -75,16 +75,15 @@ static void msg_vprint(intf_thread_t *p_intf, const char *psz_fmt, va_list args)
     fd = sys->fd;
     if (fd != -1)
     {
-        char fmt_eol[strlen (psz_fmt) + 3], *msg;
-        int len;
+        char *msg;
+        int len = vasprintf(&msg, psz_fmt, args);
 
-        snprintf(fmt_eol, sizeof (fmt_eol), "%s\r\n", psz_fmt);
-        len = vasprintf(&msg, fmt_eol, args);
-
-        if (len < 0)
+        if (unlikely(len < 0))
             return;
 
-        vlc_write(sys->fd, msg, len);
+        struct iovec iov[2] = { { msg, len }, { (char *)"\n", 1 } };
+
+        vlc_writev(sys->fd, iov, ARRAY_SIZE(iov));
         free(msg);
     }
     vlc_mutex_unlock(&sys->output_lock);



More information about the vlc-commits mailing list