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:
@@ -252,10 +252,15 @@ int bus_error_setfv(sd_bus_error *e, const char *name, const char *format, va_li
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* If we hit OOM on formatting the pretty message, we ignore
|
||||
* this, since we at least managed to write the error name */
|
||||
if (format)
|
||||
(void) vasprintf((char**) &e->message, format, ap);
|
||||
if (format) {
|
||||
_cleanup_free_ char *mesg = NULL;
|
||||
|
||||
/* If we hit OOM on formatting the pretty message, we ignore
|
||||
* this, since we at least managed to write the error name */
|
||||
|
||||
if (vasprintf(&mesg, format, ap) >= 0)
|
||||
e->message = TAKE_PTR(mesg);
|
||||
}
|
||||
|
||||
e->_need_free = 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user