summaryrefslogtreecommitdiff
path: root/src/core/unit-printf.c
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2014-07-25 15:38:31 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-07-26 15:08:41 -0400
commit7de80bfe2e61d5818601ccfddbadad3b7703ed70 (patch)
treeb8b90c03198f2f2125d13e175b2223e6239894f0 /src/core/unit-printf.c
parent6d314eca15f6cbda38d82774b210f784d3d4f52a (diff)
Always check asprintf return code
There is a small number of the places in sources where we don't check asprintf() return code and assume that after error the function returns NULL pointer via the first argument. That's wrong, after error the content of pointer is undefined.
Diffstat (limited to 'src/core/unit-printf.c')
-rw-r--r--src/core/unit-printf.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/core/unit-printf.c b/src/core/unit-printf.c
index 5bd30f0bf7..62599d0813 100644
--- a/src/core/unit-printf.c
+++ b/src/core/unit-printf.c
@@ -182,7 +182,7 @@ static int specifier_user_name(char specifier, void *data, void *userdata, char
char *printed = NULL;
Unit *u = userdata;
ExecContext *c;
- int r;
+ int r = 0;
assert(u);
@@ -208,7 +208,7 @@ static int specifier_user_name(char specifier, void *data, void *userdata, char
if (r < 0)
return -ENODATA;
- asprintf(&printed, UID_FMT, uid);
+ r = asprintf(&printed, UID_FMT, uid);
}
}
@@ -231,10 +231,10 @@ static int specifier_user_name(char specifier, void *data, void *userdata, char
if (specifier == 'u')
printed = strdup(username);
else
- asprintf(&printed, UID_FMT, uid);
+ r = asprintf(&printed, UID_FMT, uid);
}
- if (!printed)
+ if (r < 0 || !printed)
return -ENOMEM;
*ret = printed;