From b88b278394d0d3ac47d04a40876bc322491a4b83 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 9 Feb 2025 10:16:27 +0100 Subject: misc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- close_range.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'close_range.c') diff --git a/close_range.c b/close_range.c index 540eba0..29602c9 100644 --- a/close_range.c +++ b/close_range.c @@ -73,7 +73,8 @@ libsimple_close_range(unsigned int first, unsigned int last, unsigned int *next) { int saved_errno; - *next = first; + if (next) + *next = first; if (first > last) { errno = EINVAL; @@ -103,10 +104,12 @@ libsimple_close_range(unsigned int first, unsigned int last, unsigned int *next) qsort(fds, n, sizeof(*fds), uintpcmp); for (i = 0; i < n; i++) { if (close((int)fds[i]) && errno != EBADF) { - if (i + 1 < n) - *next = fds[i + 1]; - else - *next = fds[i] + (fds[i] < LIBSIMPLE_CLOSE_RANGE_MAX); + if (next) { + if (i + 1 < n) + *next = fds[i + 1]; + else + *next = fds[i] + (fds[i] < LIBSIMPLE_CLOSE_RANGE_MAX); + } free(fds); return -1; } @@ -118,13 +121,15 @@ libsimple_close_range(unsigned int first, unsigned int last, unsigned int *next) fallback: do { if (close((int)first) && errno != EBADF) { - *next = first + (first < LIBSIMPLE_CLOSE_RANGE_MAX); + if (next) + *next = first + (first < LIBSIMPLE_CLOSE_RANGE_MAX); return -1; } } while (first++ < last); out: - *next = last + (last < LIBSIMPLE_CLOSE_RANGE_MAX); + (next) + *next = last + (last < LIBSIMPLE_CLOSE_RANGE_MAX); errno = saved_errno; return 0; } -- cgit v1.2.3-70-g09d2