1- #define  DISABLE_SIGN_COMPARE_WARNINGS 
2- 
31#include  "git-compat-util.h" 
42#include  "string-list.h" 
53
@@ -17,19 +15,19 @@ void string_list_init_dup(struct string_list *list)
1715
1816/* if there is no exact match, point to the index where the entry could be 
1917 * inserted */ 
20- static  int  get_entry_index (const  struct  string_list  * list , const  char  * string ,
21- 		int  * exact_match )
18+ static  size_t  get_entry_index (const  struct  string_list  * list , const  char  * string ,
19+ 			       int  * exact_match )
2220{
23- 	int  left  =  -1 , right  =  list -> nr ;
21+ 	size_t  left  =  0 , right  =  list -> nr ;
2422	compare_strings_fn  cmp  =  list -> cmp  ? list -> cmp  : strcmp ;
2523
26- 	while  (left  +   1   <  right ) {
27- 		int  middle  =  left  +  (right  -  left ) / 2 ;
24+ 	while  (left  <  right ) {
25+ 		size_t  middle  =  left  +  (right  -  left ) / 2 ;
2826		int  compare  =  cmp (string , list -> items [middle ].string );
2927		if  (compare  <  0 )
3028			right  =  middle ;
3129		else  if  (compare  >  0 )
32- 			left  =  middle ;
30+ 			left  =  middle   +   1 ;
3331		else  {
3432			* exact_match  =  1 ;
3533			return  middle ;
@@ -40,14 +38,13 @@ static int get_entry_index(const struct string_list *list, const char *string,
4038	return  right ;
4139}
4240
43- /* returns -1-index if already exists */ 
44- static  int  add_entry (int  insert_at , struct  string_list  * list , const  char  * string )
41+ static  size_t  add_entry (struct  string_list  * list , const  char  * string )
4542{
4643	int  exact_match  =  0 ;
47- 	int  index  =   insert_at   !=   -1  ?  insert_at  :  get_entry_index (list , string , & exact_match );
44+ 	size_t  index  =  get_entry_index (list , string , & exact_match );
4845
4946	if  (exact_match )
50- 		return  -1   -   index ;
47+ 		return  index ;
5148
5249	ALLOC_GROW (list -> items , list -> nr + 1 , list -> alloc );
5350	if  (index  <  list -> nr )
@@ -63,10 +60,7 @@ static int add_entry(int insert_at, struct string_list *list, const char *string
6360
6461struct  string_list_item  * string_list_insert (struct  string_list  * list , const  char  * string )
6562{
66- 	int  index  =  add_entry (-1 , list , string );
67- 
68- 	if  (index  <  0 )
69- 		index  =  -1  -  index ;
63+ 	size_t  index  =  add_entry (list , string );
7064
7165	return  list -> items  +  index ;
7266}
@@ -116,9 +110,9 @@ struct string_list_item *string_list_lookup(struct string_list *list, const char
116110void  string_list_remove_duplicates (struct  string_list  * list , int  free_util )
117111{
118112	if  (list -> nr  >  1 ) {
119- 		int   src ,  dst ;
113+ 		size_t   dst   =   1 ;
120114		compare_strings_fn  cmp  =  list -> cmp  ? list -> cmp  : strcmp ;
121- 		for  (src   =   dst  =  1 ; src  <  list -> nr ; src ++ ) {
115+ 		for  (size_t   src  =  1 ; src  <  list -> nr ; src ++ ) {
122116			if  (!cmp (list -> items [dst  -  1 ].string , list -> items [src ].string )) {
123117				if  (list -> strdup_strings )
124118					free (list -> items [src ].string );
@@ -134,8 +128,8 @@ void string_list_remove_duplicates(struct string_list *list, int free_util)
134128int  for_each_string_list (struct  string_list  * list ,
135129			 string_list_each_func_t  fn , void  * cb_data )
136130{
137- 	int  i ,  ret  =  0 ;
138- 	for  (i  =  0 ; i  <  list -> nr ; i ++ )
131+ 	int  ret  =  0 ;
132+ 	for  (size_t   i  =  0 ; i  <  list -> nr ; i ++ )
139133		if  ((ret  =  fn (& list -> items [i ], cb_data )))
140134			break ;
141135	return  ret ;
@@ -144,8 +138,8 @@ int for_each_string_list(struct string_list *list,
144138void  filter_string_list (struct  string_list  * list , int  free_util ,
145139			string_list_each_func_t  want , void  * cb_data )
146140{
147- 	int   src ,  dst  =  0 ;
148- 	for  (src  =  0 ; src  <  list -> nr ; src ++ ) {
141+ 	size_t  dst  =  0 ;
142+ 	for  (size_t   src  =  0 ; src  <  list -> nr ; src ++ ) {
149143		if  (want (& list -> items [src ], cb_data )) {
150144			list -> items [dst ++ ] =  list -> items [src ];
151145		} else  {
@@ -171,13 +165,12 @@ void string_list_remove_empty_items(struct string_list *list, int free_util)
171165void  string_list_clear (struct  string_list  * list , int  free_util )
172166{
173167	if  (list -> items ) {
174- 		int  i ;
175168		if  (list -> strdup_strings ) {
176- 			for  (i  =  0 ; i  <  list -> nr ; i ++ )
169+ 			for  (size_t   i  =  0 ; i  <  list -> nr ; i ++ )
177170				free (list -> items [i ].string );
178171		}
179172		if  (free_util ) {
180- 			for  (i  =  0 ; i  <  list -> nr ; i ++ )
173+ 			for  (size_t   i  =  0 ; i  <  list -> nr ; i ++ )
181174				free (list -> items [i ].util );
182175		}
183176		free (list -> items );
@@ -189,13 +182,12 @@ void string_list_clear(struct string_list *list, int free_util)
189182void  string_list_clear_func (struct  string_list  * list , string_list_clear_func_t  clearfunc )
190183{
191184	if  (list -> items ) {
192- 		int  i ;
193185		if  (clearfunc ) {
194- 			for  (i  =  0 ; i  <  list -> nr ; i ++ )
186+ 			for  (size_t   i  =  0 ; i  <  list -> nr ; i ++ )
195187				clearfunc (list -> items [i ].util , list -> items [i ].string );
196188		}
197189		if  (list -> strdup_strings ) {
198- 			for  (i  =  0 ; i  <  list -> nr ; i ++ )
190+ 			for  (size_t   i  =  0 ; i  <  list -> nr ; i ++ )
199191				free (list -> items [i ].string );
200192		}
201193		free (list -> items );
0 commit comments