tree-wide: do not use (void) asprintf
asprintf(3) says that the pointer is "undefined" after a failed call. In the current glibc implementation it is just NULL. In principle the call could return a valid pointer with bad contents or something. We have two styles of error handling: in a majority of cases we would check the return value, but sometimes we used (void) and relied on the pointer not being set. In practice both styles should be equivalent, but gcc doesn't like the second one with -Wunused-result. (Though only sometimes. E.g. on my F34 box I don't get the same warnings as in CI, even though the compiler version is very similar and the compilation options are the same…). It's also nice to be consistent in our code base. So let's always use the first style of error checking.
This commit is contained in:
@@ -300,26 +300,26 @@ int rlimit_parse(int resource, const char *val, struct rlimit *ret) {
|
||||
}
|
||||
|
||||
int rlimit_format(const struct rlimit *rl, char **ret) {
|
||||
char *s = NULL;
|
||||
_cleanup_free_ char *s = NULL;
|
||||
int r;
|
||||
|
||||
assert(rl);
|
||||
assert(ret);
|
||||
|
||||
if (rl->rlim_cur >= RLIM_INFINITY && rl->rlim_max >= RLIM_INFINITY)
|
||||
s = strdup("infinity");
|
||||
r = free_and_strdup(&s, "infinity");
|
||||
else if (rl->rlim_cur >= RLIM_INFINITY)
|
||||
(void) asprintf(&s, "infinity:" RLIM_FMT, rl->rlim_max);
|
||||
r = asprintf(&s, "infinity:" RLIM_FMT, rl->rlim_max);
|
||||
else if (rl->rlim_max >= RLIM_INFINITY)
|
||||
(void) asprintf(&s, RLIM_FMT ":infinity", rl->rlim_cur);
|
||||
r = asprintf(&s, RLIM_FMT ":infinity", rl->rlim_cur);
|
||||
else if (rl->rlim_cur == rl->rlim_max)
|
||||
(void) asprintf(&s, RLIM_FMT, rl->rlim_cur);
|
||||
r = asprintf(&s, RLIM_FMT, rl->rlim_cur);
|
||||
else
|
||||
(void) asprintf(&s, RLIM_FMT ":" RLIM_FMT, rl->rlim_cur, rl->rlim_max);
|
||||
|
||||
if (!s)
|
||||
r = asprintf(&s, RLIM_FMT ":" RLIM_FMT, rl->rlim_cur, rl->rlim_max);
|
||||
if (r < 0)
|
||||
return -ENOMEM;
|
||||
|
||||
*ret = s;
|
||||
*ret = TAKE_PTR(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user