loplugin:loopvartoosmall
And while at it, merge the change from e2bd5afd72
"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
This commit is contained in:
@@ -23,7 +23,6 @@
|
|||||||
#include <sal/config.h>
|
#include <sal/config.h>
|
||||||
|
|
||||||
#if defined MACOSX
|
#if defined MACOSX
|
||||||
#include <algorithm>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <unistd.h>
|
#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
|
// macOS appears to have no better interface to close all fds (like
|
||||||
// closefrom):
|
// closefrom):
|
||||||
long openMax = sysconf(_SC_OPEN_MAX);
|
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
|
// When LibreOffice restarts itself on macOS 11 beta on arm64, for
|
||||||
// some reason sysconf(_SC_OPEN_MAX) returns 0x7FFFFFFFFFFFFFFF,
|
// some reason sysconf(_SC_OPEN_MAX) returns 0x7FFFFFFFFFFFFFFF,
|
||||||
// so use a sanity limit here.
|
// 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;
|
struct stat s;
|
||||||
if (fstat(fd, &s) != -1 && S_ISREG(s.st_mode))
|
if (fstat(fd, &s) != -1 && S_ISREG(s.st_mode))
|
||||||
close(fd);
|
close(fd);
|
||||||
|
Reference in New Issue
Block a user