Skip to content

Commit 1ae9100

Browse files
shejialuogitster
authored andcommitted
string-list: remove unused "insert_at" parameter from add_entry
In "add_entry", we accept "insert_at" parameter which must be either -1 (auto) or between 0 and `list->nr` inclusive. Any other value is invalid. When caller specify any invalid "insert_at" value, we won't check the range and move the element, which would definitely cause the trouble. However, we only use "add_entry" in "string_list_insert" function and we always pass the "-1" for "insert_at" parameter. So, we never use this parameter to insert element in a user specified position. Let's delete this parameter. If there is any requirement later, we need to use a better way to do this. Signed-off-by: shejialuo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9916313 commit 1ae9100

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

string-list.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ static int get_entry_index(const struct string_list *list, const char *string,
4141
}
4242

4343
/* returns -1-index if already exists */
44-
static int add_entry(int insert_at, struct string_list *list, const char *string)
44+
static int add_entry(struct string_list *list, const char *string)
4545
{
4646
int exact_match = 0;
47-
int index = insert_at != -1 ? insert_at : get_entry_index(list, string, &exact_match);
47+
int index = get_entry_index(list, string, &exact_match);
4848

4949
if (exact_match)
5050
return -1 - index;
@@ -63,7 +63,7 @@ static int add_entry(int insert_at, struct string_list *list, const char *string
6363

6464
struct string_list_item *string_list_insert(struct string_list *list, const char *string)
6565
{
66-
int index = add_entry(-1, list, string);
66+
int index = add_entry(list, string);
6767

6868
if (index < 0)
6969
index = -1 - index;

0 commit comments

Comments
 (0)