From 93f549dd43071d2eb23ded2e625f5160ecd85377 Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Sat, 29 Jun 2019 08:31:23 +0000 Subject: Check asprintf() return values correctly. ok and tweaks tb@ --- xenodm/dm.c | 8 +++++--- xenodm/util.c | 5 ++--- 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; } -- cgit v1.2.3