From: Lennart Poettering Date: Thu, 20 May 2021 19:26:56 +0000 (+0200) Subject: fileio: make return parameters of read_virtual_file() optional X-Git-Tag: v249-rc1~183^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f267c3142a43562d273e4cfdd05df21ed836d48b;p=thirdparty%2Fsystemd.git fileio: make return parameters of read_virtual_file() optional Prompted by: #19647 --- diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 0df03077d3c..853e679aaa8 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -371,8 +371,6 @@ int read_virtual_file(const char *filename, size_t max_size, char **ret_contents int n_retries; bool truncated = false; - assert(ret_contents); - /* Virtual filesystems such as sysfs or procfs use kernfs, and kernfs can work with two sorts of * virtual files. One sort uses "seq_file", and the results of the first read are buffered for the * second read. The other sort uses "raw" reads which always go direct to the device. In the latter @@ -486,7 +484,9 @@ int read_virtual_file(const char *filename, size_t max_size, char **ret_contents return -EBADMSG; buf[n] = 0; - *ret_contents = TAKE_PTR(buf); + + if (ret_contents) + *ret_contents = TAKE_PTR(buf); return !truncated; }