From f3ccd20bd6393b05c9949810feb0e0b366b86348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 27 Sep 2016 23:50:42 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20narrowing=20conversion=20of=20=E2=80=98-1?= =?UTF-8?q?=E2=80=99=20from=20=E2=80=98int=E2=80=99=20to=20=E2=80=98rlim?= =?UTF-8?q?=5Ft=E2=80=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We were using -1 as a sentinel to determine if we had computed the file descriptor limit, but rlim_t is unsigned. Also, RLIM_INFINITY is typically -1 as well, so the choice of -1 as a sentinel was probably not a good idea anyways. Closes issue #19. --- sparsebundlefs.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sparsebundlefs.cpp b/sparsebundlefs.cpp index fa5b0e9..749cc96 100644 --- a/sparsebundlefs.cpp +++ b/sparsebundlefs.cpp @@ -332,9 +332,12 @@ static int sparsebundle_read_buf(const char *path, struct fuse_bufvec **bufp, syslog(LOG_DEBUG, "asked to read %zu bytes at offset %ju using zero-copy read", length, uintmax_t(offset)); - static struct rlimit fd_limit = { -1, -1 }; - if (fd_limit.rlim_cur < 0) + static struct rlimit fd_limit; + static bool fd_limit_computed = false; + if (!fd_limit_computed) { getrlimit(RLIMIT_NOFILE, &fd_limit); + fd_limit_computed = true; + } sparsebundle_t *sparsebundle = sparsebundle_current(); if (sparsebundle->open_files.size() + 1 >= fd_limit.rlim_cur) {