Gentoo Archives: gentoo-commits

From: Fabian Groffen <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/, /
Date: Fri, 23 Mar 2018 11:56:21
Message-Id: 1521806126.beb68b28d4694aa576d0e06fc37deb31d83cef80.grobian@gentoo
1 commit: beb68b28d4694aa576d0e06fc37deb31d83cef80
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Fri Mar 23 11:55:26 2018 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Fri Mar 23 11:55:26 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=beb68b28
7
8 getline: fix comparison of integers of different signs
9
10 Just use an int to store getline return, then ensure it is positive,
11 such that a cast to size_t is guaranteed to result in the same value.
12
13 libq/profile.c | 7 ++++---
14 qcache.c | 14 ++++++++------
15 qlop.c | 17 ++++++++++-------
16 qmerge.c | 14 ++++++++------
17 qsearch.c | 12 +++++++-----
18 quse.c | 29 ++++++++++++++++++-----------
19 6 files changed, 55 insertions(+), 38 deletions(-)
20
21 diff --git a/libq/profile.c b/libq/profile.c
22 index c954ba6..ad631a1 100644
23 --- a/libq/profile.c
24 +++ b/libq/profile.c
25 @@ -6,7 +6,8 @@ q_profile_walk_at(int dir_fd, const char *dir, const char *file,
26 {
27 FILE *fp;
28 int subdir_fd, fd;
29 - size_t buflen, linelen;
30 + int linelen;
31 + size_t buflen;
32 char *buf;
33
34 /* Pop open this profile dir */
35 @@ -46,10 +47,10 @@ q_profile_walk_at(int dir_fd, const char *dir, const char *file,
36 }
37
38 buf = NULL;
39 - while ((linelen = getline(&buf, &buflen, fp)) != -1) {
40 + while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
41 char *s;
42
43 - rmspace_len(buf, linelen);
44 + rmspace_len(buf, (size_t)linelen);
45
46 s = strchr(buf, '#');
47 if (s)
48
49 diff --git a/qcache.c b/qcache.c
50 index 7cd100e..0082e5b 100644
51 --- a/qcache.c
52 +++ b/qcache.c
53 @@ -220,7 +220,8 @@ qcache_read_cache_file(const char *filename)
54 char *buf;
55 FILE *f;
56 portage_cache *ret = NULL;
57 - size_t len, buflen, linelen;
58 + int linelen;
59 + size_t len, buflen;
60
61 if ((f = fopen(filename, "r")) == NULL)
62 goto err;
63 @@ -234,8 +235,8 @@ qcache_read_cache_file(const char *filename)
64 len = sizeof(*ret) + s.st_size + 1;
65 ret = xzalloc(len);
66
67 - while ((linelen = getline(&buf, &buflen, f)) != -1) {
68 - rmspace_len(buf, linelen);
69 + while ((linelen = getline(&buf, &buflen, f)) >= 0) {
70 + rmspace_len(buf, (size_t)linelen);
71
72 if (strncmp(buf, "DEPEND=", 7) == 0)
73 ret->DEPEND = xstrdup(buf + 7);
74 @@ -868,7 +869,8 @@ qcache_load_arches(const char *overlay)
75 {
76 FILE *fp;
77 char *filename, *s;
78 - size_t buflen, linelen;
79 + int linelen;
80 + size_t buflen;
81 char *buf;
82
83 xasprintf(&filename, "%s/profiles/arch.list", overlay);
84 @@ -879,8 +881,8 @@ qcache_load_arches(const char *overlay)
85 archlist_count = 0;
86 arch_longest_len = 0;
87 buf = NULL;
88 - while ((linelen = getline(&buf, &buflen, fp)) != -1) {
89 - rmspace_len(buf, linelen);
90 + while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
91 + rmspace_len(buf, (size_t)linelen);
92
93 if ((s = strchr(buf, '#')) != NULL)
94 *s = '\0';
95
96 diff --git a/qlop.c b/qlop.c
97 index f0c35b7..5be2ddd 100644
98 --- a/qlop.c
99 +++ b/qlop.c
100 @@ -232,7 +232,8 @@ show_emerge_history(int listflag, array_t *atoms, const char *logfile,
101 time_t start_time, time_t end_time)
102 {
103 FILE *fp;
104 - size_t buflen, linelen;
105 + int linelen;
106 + size_t buflen;
107 char *buf, merged;
108 char *p, *q;
109 bool showit;
110 @@ -246,16 +247,17 @@ show_emerge_history(int listflag, array_t *atoms, const char *logfile,
111 }
112
113 buf = NULL;
114 - while ((linelen = getline(&buf, &buflen, fp)) != -1) {
115 + while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
116 if (linelen < 30)
117 continue;
118
119 - rmspace_len(buf, linelen);
120 + rmspace_len(buf, (size_t)linelen);
121 if ((p = strchr(buf, ':')) == NULL)
122 continue;
123 *p = 0;
124 q = p + 3;
125 - /* Make sure there's leading white space and not a truncated string. #573106 */
126 + /* Make sure there's leading white space and not a truncated
127 + * string. #573106 */
128 if (p[1] != ' ' || p[2] != ' ')
129 continue;
130
131 @@ -331,7 +333,8 @@ static void
132 show_sync_history(const char *logfile, time_t start_time, time_t end_time)
133 {
134 FILE *fp;
135 - size_t buflen, linelen;
136 + int linelen;
137 + size_t buflen;
138 char *buf, *p;
139 time_t t;
140
141 @@ -342,7 +345,7 @@ show_sync_history(const char *logfile, time_t start_time, time_t end_time)
142
143 buf = NULL;
144 /* Just find the finish lines. */
145 - while ((linelen = getline(&buf, &buflen, fp)) != -1) {
146 + while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
147 /* This cuts out like ~10% of the log. */
148 if (linelen < 35)
149 continue;
150 @@ -356,7 +359,7 @@ show_sync_history(const char *logfile, time_t start_time, time_t end_time)
151 continue;
152 p += 19;
153
154 - rmspace_len(buf, linelen);
155 + rmspace_len(buf, (size_t)linelen);
156
157 t = (time_t)atol(buf);
158 if (t < start_time || t > end_time)
159
160 diff --git a/qmerge.c b/qmerge.c
161 index 1f75acc..960a9a4 100644
162 --- a/qmerge.c
163 +++ b/qmerge.c
164 @@ -1653,7 +1653,8 @@ static int
165 parse_packages(queue *todo)
166 {
167 FILE *fp;
168 - size_t buflen, linelen;
169 + int linelen;
170 + size_t buflen;
171 char *buf, *p;
172 struct pkg_t Pkg;
173 depend_atom *pkg_atom;
174 @@ -1665,8 +1666,8 @@ parse_packages(queue *todo)
175 repo[0] = '\0';
176
177 /* First consume the header with the common data. */
178 - while ((linelen = getline(&buf, &buflen, fp)) != -1) {
179 - rmspace_len(buf, linelen);
180 + while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
181 + rmspace_len(buf, (size_t)linelen);
182 if (buf[0] == '\0')
183 break;
184
185 @@ -1785,7 +1786,8 @@ static queue *
186 qmerge_add_set_file(const char *dir, const char *file, queue *set)
187 {
188 FILE *fp;
189 - size_t buflen, linelen;
190 + int linelen;
191 + size_t buflen;
192 char *buf, *fname;
193
194 /* Find the file to read */
195 @@ -1800,8 +1802,8 @@ qmerge_add_set_file(const char *dir, const char *file, queue *set)
196
197 /* Load each entry */
198 buf = NULL;
199 - while ((linelen = getline(&buf, &buflen, fp)) != -1) {
200 - rmspace_len(buf, linelen);
201 + while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
202 + rmspace_len(buf, (size_t)linelen);
203 set = add_set(buf, set);
204 }
205 free(buf);
206
207 diff --git a/qsearch.c b/qsearch.c
208 index 1ebfccf..c2b2ebe 100644
209 --- a/qsearch.c
210 +++ b/qsearch.c
211 @@ -101,8 +101,9 @@ qsearch_ebuild_ebuild(int overlay_fd, const char *ebuild, const char *search_me,
212 }
213
214 char *buf = NULL;
215 - size_t buflen, linelen;
216 - while ((linelen = getline(&buf, &buflen, ebuildfp)) != -1) {
217 + int linelen;
218 + size_t buflen;
219 + while ((linelen = getline(&buf, &buflen, ebuildfp)) >= 0) {
220 if (linelen <= search_len)
221 continue;
222 if (strncmp(buf, search_var, search_len) != 0)
223 @@ -194,10 +195,11 @@ int qsearch_main(int argc, char **argv)
224 continue;
225 }
226
227 - size_t buflen, linelen;
228 + int linelen;
229 + size_t buflen;
230 char *buf = NULL;
231 - while ((linelen = getline(&buf, &buflen, fp)) != -1) {
232 - rmspace_len(buf, linelen);
233 + while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
234 + rmspace_len(buf, (size_t)linelen);
235 if (!buf[0])
236 continue;
237
238
239 diff --git a/quse.c b/quse.c
240 index 81d99d8..ea8a326 100644
241 --- a/quse.c
242 +++ b/quse.c
243 @@ -82,7 +82,8 @@ static void
244 quse_describe_flag(const char *overlay, unsigned int ind, unsigned int argc, char **argv)
245 {
246 #define NUM_SEARCH_FILES ARRAY_SIZE(search_files)
247 - size_t buflen, linelen;
248 + int linelen;
249 + size_t buflen;
250 char *buf, *p;
251 unsigned int i, f;
252 size_t s;
253 @@ -110,8 +111,8 @@ quse_describe_flag(const char *overlay, unsigned int ind, unsigned int argc, cha
254 if (fp[f] == NULL)
255 continue;
256
257 - while ((linelen = getline(&buf, &buflen, fp[f])) != -1) {
258 - rmspace_len(buf, linelen);
259 + while ((linelen = getline(&buf, &buflen, fp[f])) >= 0) {
260 + rmspace_len(buf, (size_t)linelen);
261 if (buf[0] == '#' || buf[0] == '\0')
262 continue;
263
264 @@ -119,7 +120,9 @@ quse_describe_flag(const char *overlay, unsigned int ind, unsigned int argc, cha
265 case 0: /* Global use.desc */
266 if (!strncmp(buf, argv[i], s))
267 if (buf[s] == ' ' && buf[s + 1] == '-') {
268 - printf(" %sglobal%s:%s%s%s: %s\n", BOLD, NORM, BLUE, argv[i], NORM, buf + s + 3);
269 + printf(" %sglobal%s:%s%s%s: %s\n",
270 + BOLD, NORM, BLUE, argv[i], NORM,
271 + buf + s + 3);
272 goto skip_file;
273 }
274 break;
275 @@ -131,14 +134,17 @@ quse_describe_flag(const char *overlay, unsigned int ind, unsigned int argc, cha
276 if (!strncmp(p, argv[i], s)) {
277 if (p[s] == ' ' && p[s + 1] == '-') {
278 *p = '\0';
279 - printf(" %slocal%s:%s%s%s:%s%s%s %s\n", BOLD, NORM, BLUE, argv[i], NORM, BOLD, buf, NORM, p + s + 3);
280 + printf(" %slocal%s:%s%s%s:%s%s%s %s\n",
281 + BOLD, NORM, BLUE, argv[i], NORM,
282 + BOLD, buf, NORM, p + s + 3);
283 }
284 }
285 break;
286
287 case 2: /* Architectures arch.list */
288 if (!strcmp(buf, argv[i])) {
289 - printf(" %sarch%s:%s%s%s: %s architecture\n", BOLD, NORM, BLUE, argv[i], NORM, argv[i]);
290 + printf(" %sarch%s:%s%s%s: %s architecture\n",
291 + BOLD, NORM, BLUE, argv[i], NORM, argv[i]);
292 goto skip_file;
293 }
294 break;
295 @@ -191,8 +197,8 @@ quse_describe_flag(const char *overlay, unsigned int ind, unsigned int argc, cha
296 /* Chop the trailing .desc for better display */
297 *p = '\0';
298
299 - while ((linelen = getline(&buf, &buflen, fp[0])) != -1) {
300 - rmspace_len(buf, linelen);
301 + while ((linelen = getline(&buf, &buflen, fp[0])) >= 0) {
302 + rmspace_len(buf, (size_t)linelen);
303 if (buf[0] == '#' || buf[0] == '\0')
304 continue;
305
306 @@ -231,7 +237,8 @@ int quse_main(int argc, char **argv)
307 char buf1[_Q_PATH_MAX];
308 char buf2[_Q_PATH_MAX];
309
310 - size_t ebuildlen, linelen;
311 + int linelen;
312 + size_t ebuildlen;
313 char *ebuild;
314
315 const char *search_var = NULL;
316 @@ -279,11 +286,11 @@ int quse_main(int argc, char **argv)
317 int overlay_fd = open(overlay, O_RDONLY|O_CLOEXEC|O_PATH);
318
319 ebuild = NULL;
320 - while ((linelen = getline(&ebuild, &ebuildlen, fp)) != -1) {
321 + while ((linelen = getline(&ebuild, &ebuildlen, fp)) >= 0) {
322 FILE *newfp;
323 int fd;
324
325 - rmspace_len(ebuild, linelen);
326 + rmspace_len(ebuild, (size_t)linelen);
327
328 fd = openat(overlay_fd, ebuild, O_RDONLY|O_CLOEXEC);
329 if (fd < 0)