Commit f2f940a
string-list: fix sign compare warnings
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, which could be simply fixed by changing the `int` type to
`size_t` type.
However, for "string-list.c::add_entry" function, we compare the `index`
of the `int` type with the `list->nr` of unsigned type. It seems that
we could just simply convert the type of `index` from `int` to
`size_t`. But actually this is a correct behavior.
We would set the `index` value by checking whether `insert_at` is -1.
If not, we would set `index` to be `insert_at`, otherwise we would use
"get_entry_index` to find the inserted position.
What if the caller passes a negative value except "-1", the compiler
would convert the `index` to be a positive value which would make the
`if` statement be false to avoid moving array. However, we would
definitely encounter trouble when setting the inserted item.
And we only call "add_entry" in "string_list_insert" function, and we
simply pass "-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 may use a better
way to do this. And then we could safely convert the index to be
`size_t` when comparing.
Signed-off-by: shejialuo <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>1 parent 683c54c commit f2f940a
1 file changed
+13
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | 1 | | |
4 | 2 | | |
5 | 3 | | |
| |||
41 | 39 | | |
42 | 40 | | |
43 | 41 | | |
44 | | - | |
| 42 | + | |
45 | 43 | | |
46 | 44 | | |
47 | | - | |
| 45 | + | |
48 | 46 | | |
49 | 47 | | |
50 | 48 | | |
51 | 49 | | |
52 | 50 | | |
53 | | - | |
| 51 | + | |
54 | 52 | | |
55 | 53 | | |
56 | 54 | | |
| |||
63 | 61 | | |
64 | 62 | | |
65 | 63 | | |
66 | | - | |
| 64 | + | |
67 | 65 | | |
68 | 66 | | |
69 | 67 | | |
| |||
116 | 114 | | |
117 | 115 | | |
118 | 116 | | |
119 | | - | |
| 117 | + | |
120 | 118 | | |
121 | 119 | | |
122 | 120 | | |
| |||
134 | 132 | | |
135 | 133 | | |
136 | 134 | | |
137 | | - | |
138 | | - | |
| 135 | + | |
| 136 | + | |
139 | 137 | | |
140 | 138 | | |
141 | 139 | | |
| |||
144 | 142 | | |
145 | 143 | | |
146 | 144 | | |
147 | | - | |
148 | | - | |
| 145 | + | |
| 146 | + | |
149 | 147 | | |
150 | 148 | | |
151 | 149 | | |
| |||
171 | 169 | | |
172 | 170 | | |
173 | 171 | | |
174 | | - | |
175 | 172 | | |
176 | | - | |
| 173 | + | |
177 | 174 | | |
178 | 175 | | |
179 | 176 | | |
180 | | - | |
| 177 | + | |
181 | 178 | | |
182 | 179 | | |
183 | 180 | | |
| |||
189 | 186 | | |
190 | 187 | | |
191 | 188 | | |
192 | | - | |
193 | 189 | | |
194 | | - | |
| 190 | + | |
195 | 191 | | |
196 | 192 | | |
197 | 193 | | |
198 | | - | |
| 194 | + | |
199 | 195 | | |
200 | 196 | | |
201 | 197 | | |
| |||
0 commit comments