tImprove error checking in concat() - synk - synchronize files between hosts
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit deb721c47bda91d79cc7b7d6160a8d5b644359d6
(DIR) parent 41a5e83a69cf024c072941210d90196e213c3f9e
(HTM) Author: Willy <willyatmailoodotorg>
Date: Thu, 1 Sep 2016 08:05:57 +0200
Improve error checking in concat()
Diffstat:
M synk.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
---
(DIR) diff --git a/synk.c b/synk.c
t@@ -116,15 +116,17 @@ concat(int n, ...)
/* count args in the given array */
for (i=0; p[i]; ++i);
- /* leave room for a trailing NULL arg if we're at the last array */
+ /* Leave room for a NULL arg at the end */
i += n ? 0 : 1;
- cat = realloc(cat, (len + i) * sizeof(char *));
- if (!cat) {
+ tmp = realloc(cat, (len + i) * sizeof(char *));
+ if (!tmp) {
perror("realloc");
+ free(cat);
va_end(args);
return NULL;
}
+ cat = tmp;
memcpy(cat + len, p, i*sizeof(char *));
len += i;
}