summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-08-01 22:18:23 -0400
committerJune McEnroe <june@causal.agency>2020-08-01 22:18:58 -0400
commitbd8997ef09c7cf51d20c124e608601fab32f8f2a (patch)
tree3f2f508465c9c5503648393f7f50a27b985b215e
parentUse ldd to automatically copy libs into chroot (diff)
downloadcatgirl-bd8997ef09c7cf51d20c124e608601fab32f8f2a.tar.gz
catgirl-bd8997ef09c7cf51d20c124e608601fab32f8f2a.zip
Check return value of asprintf
On the awful operating system GNU, asprintf leaves the destination
pointer UNDEFINED on failure.
-rw-r--r--ignore.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/ignore.c b/ignore.c
index 7fecb16..d53d138 100644
--- a/ignore.c
+++ b/ignore.c
@@ -45,17 +45,19 @@ const char *ignoreAdd(const char *pattern) {
 		if (*ch == ' ') sp++;
 	}
 	char **dest = &ignore.patterns[ignore.len++];
+	int n = 0;
 	if (!ex && !sp) {
-		asprintf(dest, "%s!*@* * * *", pattern);
+		n = asprintf(dest, "%s!*@* * * *", pattern);
 	} else if (sp < 1) {
-		asprintf(dest, "%s * * *", pattern);
+		n = asprintf(dest, "%s * * *", pattern);
 	} else if (sp < 2) {
-		asprintf(dest, "%s * *", pattern);
+		n = asprintf(dest, "%s * *", pattern);
 	} else if (sp < 3) {
-		asprintf(dest, "%s *", pattern);
+		n = asprintf(dest, "%s *", pattern);
 	} else {
 		*dest = strdup(pattern);
 	}
+	if (n < 0) err(EX_OSERR, "asprintf");
 	if (!*dest) err(EX_OSERR, "strdup");
 	return *dest;
 }