Skip to content

Commit 9916313

Browse files
shejialuogitster
authored andcommitted
string-list: fix sign compare warnings for loop iterator
In "string-list.c", there are six warnings which are emitted by "Wsign-compare". And five warnings are caused by the loop iterator type mismatch. Let's fix these five warnings by changing the `int` type to `size_t` type of the loop iterator. Signed-off-by: shejialuo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 683c54c commit 9916313

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

string-list.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ struct string_list_item *string_list_lookup(struct string_list *list, const char
116116
void string_list_remove_duplicates(struct string_list *list, int free_util)
117117
{
118118
if (list->nr > 1) {
119-
int src, dst;
119+
size_t dst = 1;
120120
compare_strings_fn cmp = list->cmp ? list->cmp : strcmp;
121-
for (src = dst = 1; src < list->nr; src++) {
121+
for (size_t src = 1; src < list->nr; src++) {
122122
if (!cmp(list->items[dst - 1].string, list->items[src].string)) {
123123
if (list->strdup_strings)
124124
free(list->items[src].string);
@@ -134,8 +134,8 @@ void string_list_remove_duplicates(struct string_list *list, int free_util)
134134
int for_each_string_list(struct string_list *list,
135135
string_list_each_func_t fn, void *cb_data)
136136
{
137-
int i, ret = 0;
138-
for (i = 0; i < list->nr; i++)
137+
int ret = 0;
138+
for (size_t i = 0; i < list->nr; i++)
139139
if ((ret = fn(&list->items[i], cb_data)))
140140
break;
141141
return ret;
@@ -144,8 +144,8 @@ int for_each_string_list(struct string_list *list,
144144
void filter_string_list(struct string_list *list, int free_util,
145145
string_list_each_func_t want, void *cb_data)
146146
{
147-
int src, dst = 0;
148-
for (src = 0; src < list->nr; src++) {
147+
size_t dst = 0;
148+
for (size_t src = 0; src < list->nr; src++) {
149149
if (want(&list->items[src], cb_data)) {
150150
list->items[dst++] = list->items[src];
151151
} else {
@@ -171,13 +171,12 @@ void string_list_remove_empty_items(struct string_list *list, int free_util)
171171
void string_list_clear(struct string_list *list, int free_util)
172172
{
173173
if (list->items) {
174-
int i;
175174
if (list->strdup_strings) {
176-
for (i = 0; i < list->nr; i++)
175+
for (size_t i = 0; i < list->nr; i++)
177176
free(list->items[i].string);
178177
}
179178
if (free_util) {
180-
for (i = 0; i < list->nr; i++)
179+
for (size_t i = 0; i < list->nr; i++)
181180
free(list->items[i].util);
182181
}
183182
free(list->items);
@@ -189,13 +188,12 @@ void string_list_clear(struct string_list *list, int free_util)
189188
void string_list_clear_func(struct string_list *list, string_list_clear_func_t clearfunc)
190189
{
191190
if (list->items) {
192-
int i;
193191
if (clearfunc) {
194-
for (i = 0; i < list->nr; i++)
192+
for (size_t i = 0; i < list->nr; i++)
195193
clearfunc(list->items[i].util, list->items[i].string);
196194
}
197195
if (list->strdup_strings) {
198-
for (i = 0; i < list->nr; i++)
196+
for (size_t i = 0; i < list->nr; i++)
199197
free(list->items[i].string);
200198
}
201199
free(list->items);

0 commit comments

Comments
 (0)