summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Herrb <matthieu@cvs.openbsd.org>2019-06-29 08:31:23 +0000
committerMatthieu Herrb <matthieu@herrb.eu>2020-07-14 15:52:43 +0200
commit93f549dd43071d2eb23ded2e625f5160ecd85377 (patch)
tree7e83bc296e70aeb0433e7a87f4086c682e1f9462
parent91c3244c8408f340c546a405996f56a5fb6cf615 (diff)
Check asprintf() return values correctly. ok and tweaks tb@
-rw-r--r--xenodm/dm.c8
-rw-r--r--xenodm/util.c5
2 files changed, 7 insertions, 6 deletions
diff --git a/xenodm/dm.c b/xenodm/dm.c
index 77920b5..59a0307 100644
--- a/xenodm/dm.c
+++ b/xenodm/dm.c
@@ -502,7 +502,7 @@ SetWindowPath(struct display *d)
unsigned long bytes_after;
unsigned char *buf;
const char *windowpath;
- char *newwindowpath;
+ char *newwindowpath = NULL;
unsigned long num;
prop = XInternAtom(d->dpy, "XFree86_VT", False);
@@ -549,9 +549,11 @@ SetWindowPath(struct display *d)
XFree(buf);
windowpath = getenv("WINDOWPATH");
if (!windowpath) {
- asprintf(&newwindowpath, "ttyC%lu", num - 1);
+ if (asprintf(&newwindowpath, "ttyC%lu", num - 1) == -1)
+ return;
} else {
- asprintf(&newwindowpath, "%s:%lu", windowpath, num); /* XXX */
+ if (asprintf(&newwindowpath, "%s:%lu", windowpath, num) == -1)
+ return;
}
free(d->windowPath);
d->windowPath = newwindowpath;
diff --git a/xenodm/util.c b/xenodm/util.c
index 8f6cfe5..5097d44 100644
--- a/xenodm/util.c
+++ b/xenodm/util.c
@@ -54,12 +54,11 @@ makeEnv (const char *name, const char *value)
{
char *result;
- asprintf(&result, "%s=%s", name, value);
-
- if (!result) {
+ if (asprintf(&result, "%s=%s", name, value) == -1) {
LogOutOfMem ("makeEnv");
return NULL;
}
+
return result;
}