groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 12/13: [libbib]: Stop throwing spurious diagnostic.


From: G. Branden Robinson
Subject: [groff] 12/13: [libbib]: Stop throwing spurious diagnostic.
Date: Sat, 11 Sep 2021 16:20:14 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 3f94abf4072e46f1f2e434a0b3582961113991af
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sun Sep 12 05:30:07 2021 +1000

    [libbib]: Stop throwing spurious diagnostic.
    
    * src/libs/libbib/index.cpp (index_search_item::get_invalidity_reason):
      Don't complain about about a last list element being nonnegative if
      the list size was zero in the first place, as can happen with an empty
      index.  More seriously from a language standpoint, avoid reading
      through a negative array index (this can escape a compiler's attention
      because we're reading from the midst of a heap-allocated or `mmap()`ed
      region, but it's still a code smell).
    
    Fixes <https://savannah.gnu.org/bugs/?61144>.
---
 ChangeLog                 | 13 +++++++++++++
 src/libs/libbib/index.cpp |  2 +-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index b5a504b..fa7a83f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2021-09-12  G. Branden Robinson <g.branden.robinson@gmail.com>
 
+       * src/libs/libbib/index.cpp
+       (index_search_item::get_invalidity_reason): Don't complain about
+       about a last list element being nonnegative if the list size was
+       zero in the first place, as can happen with an empty index.
+       More seriously from a language standpoint, avoid reading through 
+       a negative array index (this can escape a compiler's attention
+       because we're reading from the midst of a heap-allocated or
+       `mmap()`ed region, but it's still a code smell).
+
+       Fixes <https://savannah.gnu.org/bugs/?61144>.
+
+2021-09-12  G. Branden Robinson <g.branden.robinson@gmail.com>
+
        * src/libs/libbib/index.cpp (index_search_item::load,
        index_search_item::get_invalidity_reason,
        index_search_item::add_out_of_date_file): Clarify diagnostic
diff --git a/src/libs/libbib/index.cpp b/src/libs/libbib/index.cpp
index 5448e80..c984a71 100644
--- a/src/libs/libbib/index.cpp
+++ b/src/libs/libbib/index.cpp
@@ -223,7 +223,7 @@ const char *index_search_item::get_invalidity_reason()
 {
   if (tags == 0)
     return "not loaded";
-  if (lists[header.lists_size - 1] >= 0)
+  if ((header.lists_size > 0) && (lists[header.lists_size - 1] >= 0))
     return "last list element not negative";
   int i;
   for (i = 0; i < header.table_size; i++) {



reply via email to

[Prev in Thread] Current Thread [Next in Thread]