From 30e5617f6bb30a85ae13990e9045ac95b8f0be4d Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Mon, 17 Aug 2020 08:18:07 +0200 Subject: [PATCH] loplugin:loopvartoosmall And while at it, merge the change from e2bd5afd726abd5df438b6b821416bd7cf496e4d "Make the C++/UNO bridge work to some extent on macOS on arm64" into the existing code in a better way, reviving the assertion that openMax will be non- negative when entering the loop. Change-Id: I4b4e173a79ae6a0bbbf07df87d46761e86f460c0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100841 Reviewed-by: Tor Lillqvist Reviewed-by: Stephan Bergmann Tested-by: Jenkins --- sal/osl/unx/salinit.cxx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/sal/osl/unx/salinit.cxx b/sal/osl/unx/salinit.cxx index c3ac48c575d1..5f75bef3ced6 100644 --- a/sal/osl/unx/salinit.cxx +++ b/sal/osl/unx/salinit.cxx @@ -23,7 +23,6 @@ #include #if defined MACOSX -#include #include #include #include @@ -69,14 +68,14 @@ void sal_detail_initialize(int argc, char ** argv) { // macOS appears to have no better interface to close all fds (like // closefrom): long openMax = sysconf(_SC_OPEN_MAX); - if (openMax == -1) { - // Some random value, but hopefully sysconf never returns -1 anyway: - openMax = 1024; - } // When LibreOffice restarts itself on macOS 11 beta on arm64, for // some reason sysconf(_SC_OPEN_MAX) returns 0x7FFFFFFFFFFFFFFF, // so use a sanity limit here. - for (int fd = 3; fd < std::min(100000l, openMax); ++fd) { + if (openMax == -1 || openMax == std::numeric_limits::max()) { + openMax = 100000; + } + assert(openMax >= 0 && openMax <= std::numeric_limits< int >::max()); + for (int fd = 3; fd < int(openMax); ++fd) { struct stat s; if (fstat(fd, &s) != -1 && S_ISREG(s.st_mode)) close(fd);