changeset 315:67392d7ef391

Slight code cleanup of siEscapeString().
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 11 Jan 2020 18:31:15 +0200
parents 71139ed7e43f
children b0c844b39516
files sidinfo.c
diffstat 1 files changed, 7 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/sidinfo.c	Sat Jan 11 18:30:51 2020 +0200
+++ b/sidinfo.c	Sat Jan 11 18:31:15 2020 +0200
@@ -701,28 +701,29 @@
 
 static char * siEscapeString(const char *str, const char *esc)
 {
+    size_t len, size;
+    char *buf;
+
     if (str == NULL)
         return NULL;
 
     if (esc == NULL)
         return th_strdup(str);
 
-    size_t len = 0, size = strlen(str) + 1;
-    char *buf = th_malloc(size);
-    if (buf == NULL)
+    size = strlen(str) + 1;
+    if ((buf = th_malloc(size)) == NULL)
         return NULL;
 
-    while (*str)
+    for (len = 0; *str; str++)
     {
         if (strchr(esc, *str) != NULL || *str == '\\')
         {
             if (!th_strbuf_putch(&buf, &size, &len, '\\'))
                 goto err;
         }
+
         if (!th_strbuf_putch(&buf, &size, &len, *str))
             goto err;
-
-        str++;
     }
 
     if (!th_strbuf_putch(&buf, &size, &len, 0))