[Libreoffice-commits] core.git: sal/osl

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Mon Aug 17 07:41:52 UTC 2020


 sal/osl/unx/salinit.cxx |   11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

New commits:
commit 30e5617f6bb30a85ae13990e9045ac95b8f0be4d
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Mon Aug 17 08:18:07 2020 +0200
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Mon Aug 17 09:41:10 2020 +0200

    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 <tml at collabora.com>
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
    Tested-by: Jenkins

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 <sal/config.h>
 
 #if defined MACOSX
-#include <algorithm>
 #include <cassert>
 #include <limits>
 #include <unistd.h>
@@ -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<long>::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);


More information about the Libreoffice-commits mailing list