summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2020-08-17 08:18:07 +0200
committerStephan Bergmann <sbergman@redhat.com>2020-08-17 09:41:10 +0200
commit30e5617f6bb30a85ae13990e9045ac95b8f0be4d (patch)
treef65c49ba5f64555a9cd418444e226df4224c09f4 /sal
parent4b1e208f3d94e4e1cf7c7eb951ceb4d023d5b7ce (diff)
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@collabora.com> Reviewed-by: Stephan Bergmann <sbergman@redhat.com> Tested-by: Jenkins
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/unx/salinit.cxx11
1 files 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 <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);