From: Lennart Poettering Date: Thu, 4 Mar 2021 14:59:46 +0000 (+0100) Subject: fileio: minor read_full_stream_full() optimization X-Git-Tag: v248-rc3~62 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a60d0647480d16e41a418adc72077098a8a3a852;p=thirdparty%2Fsystemd.git fileio: minor read_full_stream_full() optimization If we shall read as much of a file/stream as we can, then it makes sense to use the full malloc()ed memory, not just the part we asked for. --- diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 15f0ffbdfa7..596946ccf49 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -548,7 +548,9 @@ int read_full_stream_full( } buf = t; - n = n_next; + /* Unless a size has been explicitly specified, try to read as much as fits into the memory + * we allocated (minus 1, to leave one byte for the safety NUL byte) */ + n = size == SIZE_MAX ? malloc_usable_size(buf) - 1 : n_next; errno = 0; k = fread(buf + l, 1, n - l, f);