aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2023-10-11 14:39:37 +0100
committerAndrew Burgess <aburgess@redhat.com>2023-10-12 13:58:19 +0100
commit241f29fba6ab4c584eeb4e7f53302aa92d2c11f4 (patch)
treefab24539e0523b0279ed3c056d432bfcc0e5a402
parent4b41a55fe53ce2da4823ffa3a5b94bd09bf2ab0d (diff)
downloadbinutils-241f29fba6ab4c584eeb4e7f53302aa92d2c11f4.zip
binutils-241f29fba6ab4c584eeb4e7f53302aa92d2c11f4.tar.gz
binutils-241f29fba6ab4c584eeb4e7f53302aa92d2c11f4.tar.bz2
bfd/cache: change type used to track cached BFDs from int to unsigned
Within bfd/cache.c change the type for max_open_files and open_files variables from int to unsigned. As a consequence of this, the return type for bfd_cache_max_open() is also changed from int to unsigned. Within bfd_cache_max_open I've left the local 'max' variable as an int, this should ensure that if the sysconf call fails, and returns -1, then the computed max value will be less than 10, which means max_open_files will be set to 10. If 'max' was changed to unsigned then, should the sysconf call fail, we'd end up with max becoming a very large positive number ... which is clearly not what we want. And, while I was auditing how open_files is used, I added an assert within bfd_cache_delete to ensure that we don't try to reduce open_files below zero. There should be no user visible change with this commit.
-rw-r--r--bfd/cache.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/bfd/cache.c b/bfd/cache.c
index 357a38d..87c4bcd 100644
--- a/bfd/cache.c
+++ b/bfd/cache.c
@@ -67,11 +67,11 @@ enum cache_flag {
/* The maximum number of files which the cache will keep open at
one time. When needed call bfd_cache_max_open to initialize. */
-static int max_open_files = 0;
+static unsigned max_open_files = 0;
/* Set max_open_files, if not already set, to 12.5% of the allowed open
file descriptors, but at least 10, and return the value. */
-static int
+static unsigned
bfd_cache_max_open (void)
{
if (max_open_files == 0)
@@ -115,7 +115,7 @@ bfd_cache_max_open (void)
/* The number of BFD files we have open. */
-static int open_files;
+static unsigned open_files;
/* Zero, or a pointer to the topmost BFD on the chain. This is
used by the <<bfd_cache_lookup>> macro in @file{libbfd.h} to
@@ -176,6 +176,7 @@ bfd_cache_delete (bfd *abfd)
snip (abfd);
abfd->iostream = NULL;
+ BFD_ASSERT (open_files > 0);
--open_files;
abfd->flags |= BFD_CLOSED_BY_CACHE;