Fix narrowing conversion of ‘-1’ from ‘int’ to ‘rlim_t‘

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.
This commit is contained in:
Tor Arne Vestbø
2016-09-27 23:50:42 +02:00
parent 046d0153b0
commit f3ccd20bd6

View File

@@ -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) {