texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * info/echo-area.c (remove_completion_duplicates,


From: Patrice Dumas
Subject: branch master updated: * info/echo-area.c (remove_completion_duplicates, build_completions): get completions number in argument and return the new completions number.
Date: Wed, 09 Oct 2024 06:32:40 -0400

This is an automated email from the git hooks/post-receive script.

pertusus pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 4399789698 * info/echo-area.c (remove_completion_duplicates, 
build_completions): get completions number in argument and return the new 
completions number.
4399789698 is described below

commit 4399789698591fe21bc240156c2d62ca599cc2e5
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Oct 9 12:32:28 2024 +0200

    * info/echo-area.c (remove_completion_duplicates, build_completions):
    get completions number in argument and return the new completions
    number.
    
    * info/echo-area.c (build_completions): use a size_t index variable to
    add entries to completions_found.  Pass this variable to
    remove_completion_duplicates and retirieve the modified value.  Set
    completions_found_index at this point, such that the conversion to
    long is explicit, and mark in a comment that the completions_found*
    and LCD_completion should not be modified after that point and before
    a call to build_completions.
---
 ChangeLog        | 14 ++++++++++++++
 info/echo-area.c | 43 +++++++++++++++++++++++++++----------------
 2 files changed, 41 insertions(+), 16 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e25de51c2c..de9cbe1f6a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2024-10-09  Patrice Dumas  <pertusus@free.fr>
+
+       * info/echo-area.c (remove_completion_duplicates, build_completions):
+       get completions number in argument and return the new completions
+       number.
+
+       * info/echo-area.c (build_completions): use a size_t index variable to
+       add entries to completions_found.  Pass this variable to
+       remove_completion_duplicates and retirieve the modified value.  Set
+       completions_found_index at this point, such that the conversion to
+       long is explicit, and mark in a comment that the completions_found*
+       and LCD_completion should not be modified after that point and before
+       a call to build_completions.
+
 2024-10-09  Patrice Dumas  <pertusus@free.fr>
 
        * info/echo-area.c (completions_found_index)
diff --git a/info/echo-area.c b/info/echo-area.c
index a7f5d6b597..88c85b475a 100644
--- a/info/echo-area.c
+++ b/info/echo-area.c
@@ -1194,7 +1194,7 @@ static REFERENCE LCD_reference = {
     NULL, NULL, NULL, 0, 0, 0, 0
 };
 
-static void remove_completion_duplicates (void);
+static size_t remove_completion_duplicates (size_t completions_number);
 
 /* Variables which remember the state of the most recent call
    to build_completions (). */
@@ -1220,6 +1220,7 @@ build_completions (void)
   register REFERENCE *entry;
   char *request;
   int informed_of_lengthy_job = 0;
+  size_t completion_index;
 
   /* If there are no items to complete over, exit immediately. */
   if (!echo_area_completion_items)
@@ -1248,10 +1249,13 @@ build_completions (void)
   last_completion_request = request;
   last_completion_items = echo_area_completion_items;
 
-  /* Always start at the beginning of the list. */
+  /* reset */
   completions_found_index = 0;
   LCD_completion = NULL;
 
+  /* Start at the beginning of the list. */
+  completion_index = 0;
+
   for (i = 0; (entry = echo_area_completion_items[i]); i++)
     {
       /* Skip certain items (for example, we might only want
@@ -1260,22 +1264,29 @@ build_completions (void)
         continue;
 
       if (mbsncasecmp (request, entry->label, len) == 0)
-        add_pointer_to_array (entry, completions_found_index,
+        add_pointer_to_array (entry, completion_index,
                               completions_found, completions_found_slots,
                               20);
 
-      if (!informed_of_lengthy_job && completions_found_index > 100)
+      if (!informed_of_lengthy_job && completion_index > 100)
         {
           informed_of_lengthy_job = 1;
           window_message_in_echo_area (_("Building completions..."));
         }
     }
 
-  if (!completions_found_index)
+  if (!completion_index)
     return;
 
   /* Sort and prune duplicate entries from the completions array. */
-  remove_completion_duplicates ();
+  completion_index = remove_completion_duplicates (completion_index);
+
+  /* from here, completions and completions_found_index should not be
+     modified until a build_completions call.  Same for LCD_completion
+     set when the function returns just below. */
+  /* NOTE conversion from size_t to long here to be sure that comparisons with
+     windows length fields are always safe. */
+  completions_found_index = completion_index;
 
   /* If there is only one completion, just return that. */
   if (completions_found_index == 1)
@@ -1345,21 +1356,21 @@ compare_references (const void *entry1, const void 
*entry2)
 }
 
 /* Prune duplicate entries from COMPLETIONS_FOUND. */
-static void
-remove_completion_duplicates (void)
+static size_t
+remove_completion_duplicates (size_t completions_number)
 {
-  long i, j;
+  size_t i, j;
   REFERENCE **temp;
-  long newlen;         /* Should not be negative */
+  size_t newlen;
 
-  if (!completions_found_index)
-    return;
+  if (!completions_number)
+    return 0;
 
   /* Sort the items. */
-  qsort (completions_found, completions_found_index, sizeof (REFERENCE *),
+  qsort (completions_found, completions_number, sizeof (REFERENCE *),
          compare_references);
 
-  for (i = 0, newlen = 1; i < completions_found_index - 1; i++)
+  for (i = 0, newlen = 1; i < completions_number - 1; i++)
     {
       if (strcmp (completions_found[i]->label,
                   completions_found[i + 1]->label) == 0)
@@ -1371,7 +1382,7 @@ remove_completion_duplicates (void)
   /* We have marked all the dead slots.  It is faster to copy the live slots
      twice than to prune the dead slots one by one. */
   temp = xmalloc ((1 + newlen) * sizeof (REFERENCE *));
-  for (i = 0, j = 0; i < completions_found_index; i++)
+  for (i = 0, j = 0; i < completions_number; i++)
     if (completions_found[i])
       temp[j++] = completions_found[i];
 
@@ -1379,8 +1390,8 @@ remove_completion_duplicates (void)
     completions_found[i] = temp[i];
 
   completions_found[i] = NULL;
-  completions_found_index = newlen;
   free (temp);
+  return newlen;
 }
 
 /* Scroll the "other" window.  If there is a window showing completions, scroll



reply via email to

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