# HG changeset patch # User Matti Hamalainen # Date 1578760275 -7200 # Node ID 67392d7ef391deb65ff7f9ec4e6e7ecfd630852a # Parent 71139ed7e43f4e82925d45e951424815127038d1 Slight code cleanup of siEscapeString(). diff -r 71139ed7e43f -r 67392d7ef391 sidinfo.c --- 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))