]> git.ipfire.org Git - thirdparty/git.git/commitdiff
string-list: change "string_list_find_insert_index" return type to "size_t"
authorshejialuo <shejialuo@gmail.com>
Wed, 17 Sep 2025 09:20:02 +0000 (17:20 +0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 17 Sep 2025 14:55:32 +0000 (07:55 -0700)
As "string_list_find_insert_index" is a simple wrapper of
"get_entry_index" and the return type of "get_entry_index" is already
"size_t", we could simply change its return type to "size_t".

Update all callers to use size_t variables for storing the return value.
The tricky fix is the loop condition in "mailmap.c" to properly handle
"size_t" underflow by changing from `0 <= --i` to `i--`.

Remove "DISABLE_SIGN_COMPARE_WARNINGS" from "mailmap.c" as it's no
longer needed with the proper unsigned types.

Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
add-interactive.c
mailmap.c
refs.c
string-list.c
string-list.h

index 7c0fd3d218f2b87bf79ab39cbc05c565716626b2..19def3168a2839c17605ad636529e85b2dc82c28 100644 (file)
@@ -222,7 +222,7 @@ static void find_unique_prefixes(struct prefix_item_list *list)
 static ssize_t find_unique(const char *string, struct prefix_item_list *list)
 {
        bool exact_match;
-       int index = string_list_find_insert_index(&list->sorted, string, &exact_match);
+       size_t index = string_list_find_insert_index(&list->sorted, string, &exact_match);
        struct string_list_item *item;
 
        if (list->items.nr != list->sorted.nr)
index 58a4484963c6e9725a54899ea3c1bc0a71c1ba4a..37fd158a516d2571f154e1a3b72d5596422d37be 100644 (file)
--- a/mailmap.c
+++ b/mailmap.c
@@ -1,5 +1,4 @@
 #define USE_THE_REPOSITORY_VARIABLE
-#define DISABLE_SIGN_COMPARE_WARNINGS
 
 #include "git-compat-util.h"
 #include "environment.h"
@@ -244,7 +243,7 @@ static struct string_list_item *lookup_prefix(struct string_list *map,
                                              const char *string, size_t len)
 {
        bool exact_match;
-       int i = string_list_find_insert_index(map, string, &exact_match);
+       size_t i = string_list_find_insert_index(map, string, &exact_match);
        if (exact_match) {
                if (!string[len])
                        return &map->items[i];
@@ -266,7 +265,7 @@ static struct string_list_item *lookup_prefix(struct string_list *map,
         * overlong key would be inserted, which must come after the
         * real location of the key if one exists.
         */
-       while (0 <= --i && i < map->nr) {
+       while (i-- && i < map->nr) {
                int cmp = strncasecmp(map->items[i].string, string, len);
                if (cmp < 0)
                        /*
diff --git a/refs.c b/refs.c
index f1ff5bf8467f303d6214f1574eb315307d5cc794..a8f06b9a0ad1515f9575fed74bf452bc9183d115 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -1688,8 +1688,6 @@ const char *find_descendant_ref(const char *dirname,
                                const struct string_list *extras,
                                const struct string_list *skip)
 {
-       int pos;
-
        if (!extras)
                return NULL;
 
@@ -1699,7 +1697,7 @@ const char *find_descendant_ref(const char *dirname,
         * with dirname (remember, dirname includes the trailing
         * slash) and is not in skip, then we have a conflict.
         */
-       for (pos = string_list_find_insert_index(extras, dirname, NULL);
+       for (size_t pos = string_list_find_insert_index(extras, dirname, NULL);
             pos < extras->nr; pos++) {
                const char *extra_refname = extras->items[pos].string;
 
index c589ab5a2cf079de8d1e0c82cdff823eadd4a0a2..08dc00984ccbd6e72398d7e58e7a6cb7fa2e39b9 100644 (file)
@@ -91,8 +91,8 @@ bool string_list_has_string(const struct string_list *list, const char *string)
        return exact_match;
 }
 
-int string_list_find_insert_index(const struct string_list *list, const char *string,
-                                 bool *exact_match)
+size_t string_list_find_insert_index(const struct string_list *list, const char *string,
+                                    bool *exact_match)
 {
        return get_entry_index(list, string, exact_match);
 }
index 8830ce671d4fa6b5d07f7fc8cca58497cf657a04..6b0a2f475244c58e0a82d872cb3577674c400663 100644 (file)
@@ -173,8 +173,8 @@ void string_list_remove_empty_items(struct string_list *list, int free_util);
 
 /** Determine if the string_list has a given string or not. */
 bool string_list_has_string(const struct string_list *list, const char *string);
-int string_list_find_insert_index(const struct string_list *list, const char *string,
-                                 bool *exact_match);
+size_t string_list_find_insert_index(const struct string_list *list, const char *string,
+                                    bool *exact_match);
 
 /**
  * Insert a new element to the string_list. The returned pointer can