From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id F279C38582A1; Thu, 12 Oct 2023 12:59:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F279C38582A1 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: bfd-cvs@sourceware.org Subject: [binutils-gdb] bfd/cache: change type used to track cached BFDs from int to unsigned X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: 4b41a55fe53ce2da4823ffa3a5b94bd09bf2ab0d X-Git-Newrev: 241f29fba6ab4c584eeb4e7f53302aa92d2c11f4 Message-Id: <20231012125953.F279C38582A1@sourceware.org> Date: Thu, 12 Oct 2023 12:59:53 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Oct 2023 12:59:54 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D241f29fba6ab= 4c584eeb4e7f53302aa92d2c11f4 commit 241f29fba6ab4c584eeb4e7f53302aa92d2c11f4 Author: Andrew Burgess Date: Wed Oct 11 14:39:37 2023 +0100 bfd/cache: change type used to track cached BFDs from int to unsigned =20 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. =20 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. =20 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. =20 There should be no user visible change with this commit. Diff: --- bfd/cache.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bfd/cache.c b/bfd/cache.c index 357a38da599..87c4bcd3148 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. */ =20 -static int max_open_files =3D 0; +static unsigned max_open_files =3D 0; =20 /* 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 =3D=3D 0) @@ -115,7 +115,7 @@ bfd_cache_max_open (void) =20 /* The number of BFD files we have open. */ =20 -static int open_files; +static unsigned open_files; =20 /* Zero, or a pointer to the topmost BFD on the chain. This is used by the <> macro in @file{libbfd.h} to @@ -176,6 +176,7 @@ bfd_cache_delete (bfd *abfd) snip (abfd); =20 abfd->iostream =3D NULL; + BFD_ASSERT (open_files > 0); --open_files; abfd->flags |=3D BFD_CLOSED_BY_CACHE;